1071 Speech Patterns
#include<bits/stdc++.h>
using namespace std;
bool check(char c)
{
if('a'<=c && c<='z')
return true;
if('A'<=c && c<='Z')
return true;
if('0'<=c && c<='9')
return true;
return false;
}
int main()
{
string s;
getline(cin,s);
unordered_map<string,int> mp;
string res;
for(int i=0; i<s.size();i++)
if(check(s[i]))
{
int j=i;
string word;
while(j<s.size() && check(s[j]))
word+=towlower(s[j++]);
i=j;
mp[word]++;
}
string word;
int cnt=-1;
for(auto item:mp)
{
//这里不能写成item.second>=cnt && word<item.first因为见下图
if(item.second>cnt || item.second==cnt && word<item.first)
{
cnt=item.second;
word=item.first;
}
cout << word << " " << cnt << endl;
}
return 0;
}