AcWing 1557. 说话方式
原题链接
简单
作者:
Value
,
2020-07-13 21:36:21
,
所有人可见
,
阅读 512
/*
分词,其中除了数字和字母以外其他均会起到分割作用
*/
#include <iostream>
#include <map>
using namespace std;
map<string, int> mp;
bool letter(char t){
if(t >= '0' && t <= '9' || t >= 'a' && t <= 'z') return true;
return false;
}
int main(){
string s; getline(cin, s);
for(int i = 0; i < s.size(); i ++ ){
if(s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
}
string word = "";
for(int i = 0; i < s.size(); i ++ ){
if(!letter(s[i])){
if(word != "") mp[word] ++ ;
word = "";
}else{
word += s[i];
}
}
if(word != "") mp[word] ++ ;
int cnt = 0;
for(map<string, int>::iterator it = mp.begin(); it != mp.end(); it ++ ){
if(it->second > cnt){
cnt = it->second;
word = it->first;
}
}
cout << word << " " << cnt << endl;
return 0;
}