PAT 1071. Speech Patterns (25)

題目比較簡單,輸入需要讀取一整行,

吐槽一下vc6.0,讀取一整行竟然要按兩次回車才能輸入進去。

代碼如下:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
string str;

int main()
{

	getline(cin,str);
	vector<string> res;
	
	int i;
	for(i = 0;i<str.size();i++)
	{
		string temp = "";
		while((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= '0' && str[i] <= '9')
			|| (str[i] >= 'A' && str[i] <= 'Z'))
		{
			if(str[i] >= 'A' && str[i] <= 'Z')
			{
				str[i] = str[i] - 'A' + 'a';
			}
			temp += str[i];
			i++;
		}
		if(temp.size() > 0)
			res.push_back(temp);
	}

	sort(res.begin(),res.end());

	int max = 0;
	int k = 0;

	for(i = 0;i<res.size();i++)
	{
		int j = 1;
		while((i+j) < res.size() &&res[i] == res[i+j]){
			j++;
		}

		if(j > max)
		{
			max= j;
			k = i;
		}

		i = i+j-1;
	}

	cout << res[k] << " " << max << endl;
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章