有一个测试点过不去a......
代码:
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
map<string, int> pp;
bool cmp(char p)
{
return !((p >= 48 && p <= 57) || (p >= 65 && p <= 90) || (p >= 97 && p <= 122));
}
int main()
{
string st;
while (cin >> st)
{
st.erase(remove_if(st.begin(),st.end(),cmp),st.end());
for (int i = 0; i < st.length(); i++)
st[i] = tolower(st[i]);
//cout <<"st等于:"<< st << endl;
pp[st]++;
}
string result; int max = 0;
for (auto it = pp.begin(); it != pp.end(); it++)
{
if (it->second > max){
max = it->second; result = it->first;
}
if (it->second = max&&it->first < result)
{
max = it->second; result = it->first;
}
}
cout << result<<" "<<max;
return 0;
}