PATA 1071 Speech Patterns.

Posted zengq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PATA 1071 Speech Patterns.相关的知识,希望对你有一定的参考价值。

#include <bits/stdc++.h>
using namespace std;
bool check(char c)//检查是否为字母或数字
{
	if(c>=‘A‘&&c<=‘Z‘||c>=‘a‘&&c<=‘z‘||c>=‘0‘&&c<=‘9‘) 
		return true;
	else
		return false;
} 
int main()
{
	map<string,int> count;
	string str;
	getline(cin,str);
	int i = 0;
	while(i<str.length())
	{
		string word;
		while(i<str.length()&&check(str[i]))
		{
			if(str[i]>=‘A‘&&str[i]<=‘Z‘){  //大写统一改为小写
				str[i] += (‘a‘-‘A‘);
			}
			word += str[i]; //字符拼接 +
			i++;
		}		
		if(word != ""){
			if(count.find(word)==count.end())	count[word]=1;  //这单词还没出现过,计数为1
			else count[word]++;
		}
		while(i<str.length()&&!check(str[i]))  //遇到其它字符跳过
		{
			i++;
		}
	}
	string ans;
	int  MAX=0;
	for(map<string,int>::iterator it=count.begin();it != count.end();it++)  //只能用!=,而不能用<end() 
	{
		if(it->second>MAX)
		{
			ans = it->first;
			MAX = it->second;
		}
	}
	cout<<ans<<" "<<MAX<<endl;
	return 0;
	
	
}

  

以上是关于PATA 1071 Speech Patterns.的主要内容,如果未能解决你的问题,请参考以下文章

1071 Speech Patterns (25)

1071. Speech Patterns (25)

PAT Advanced 1071 Speech Patterns (25分)

1071 Speech Patterns

1071 Speech Patterns 需再做

PAT (Advanced Level) 1071. Speech Patterns (25)