1071. Speech Patterns (25)

来源:互联网 发布:管家婆软件工贸版 编辑:程序博客网 时间:2024/06/05 18:59
#include<iostream>#include<map>#include<string>using namespace std;bool check(char c){if((c>='0'&&c<='9')||(c>='a'&&c<='z')||(c>='A'&&c<='Z')) return true;else    return false;}char change(char c){if(c>='A'&&c<='Z') return c-'A'+'a'; else    return c;} 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])==true){str[i]=change(str[i]);word+=str[i];i++;}if(word!=""){//单词非空 if(count.find(word)==count.end()){   count[word]=1;    }    else{   count[word]++;    }}while(i<str.length()&&check(str[i])==false){i++;} }int maxcount=0;string maxword;for(map<string,int>::iterator it=count.begin();it!=count.end();it++){if(it->second>maxcount){maxword=it->first;maxcount=it->second;}}cout<<maxword<<" "<<maxcount<<endl;} 

0 0
原创粉丝点击