PAT 1071 Speech Patterns

来源:互联网 发布:淘宝产品上首页 编辑:程序博客网 时间:2024/04/29 04:35

     卡时间卡的比较紧

#include<algorithm>#include<cstdio>#include<iostream>#include<string>#include<cstring>#include<vector>#include<set>#include<map>#define ll long longusing namespace std;map<string,int>mp;int ok(char c){if(c>='0'&&c<='9')return 1;if(c>='a'&&c<='z')return 1;if(c>='A'&&c<='Z')return 1;return 0;}int main(){string s,ans;getline(cin,s);for(int i = 0;i<s.length();){string word;while(i<s.length()&&ok(s[i])){if(s[i]>='A'&&s[i]<='Z')s[i]+=32;word+=s[i++];}if(word!="")mp[word]++;while(i<s.length()&&!ok(s[i]))i++;}map<string,int>::iterator it;int mx = -1;for(it = mp.begin();it!=mp.end();it++){if((*it).second>mx||((*it).second == mx&&(*it).first<ans)){mx = (*it).second;ans = (*it).first;}}cout<<ans<<" "<<mx<<endl;return 0;}


0 0
原创粉丝点击