【算法笔记习题】问题 A: Speech Patterns (25)

#include 
#include 
#include 
#include 
#include 
using namespace std;

//检查单个字符——英文或者数字 
bool check(char ch)
{
	if (ch>='a'&&ch<='z') return true;
	if (ch>='A'&&ch<='Z') return true;
	if (ch>='0'&&ch<='9') return true;
	return false;//合法字符 
}

int main()
{
	mapmp;
	string s,ans;
	string word;
	getline(cin,s);//输入一串所要求的字符 
	
	for(int i=0; i='A' && s[i]<='Z')
				s[i] +=32; //转为小写字母
			word += s[i] ;//word字符串加上这个单词 
		}
		
		//非法字符 或者 字符串结束 
		if(check(s[i]) ==false || i==s.length()-1  )
		{
			if(word.length() != 0 )
				mp[word]++; //这个字符串++
			word.clear();//清空 计算下一个字符 
		}
	}
	
	int max=-1; 
	//开始遍历map
	for(map::iterator it = mp.begin(); it!=mp.end(); it++) 
		//找出最大的 
		if(it->second>max){
			max = it->second;
			ans = it->first;
		}
		
	cout<

 

你可能感兴趣的:(算法笔记习题)