#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string,int>mp;
int judge(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 str;
getline(cin,str);
string word;
int i=0;
while(i<str.length())
{
int flag=0;//判断是否word为空值
while(i<str.length()&&!judge(str[i]))i++;
while(i<str.length()&&judge(str[i]))
{
flag=1;//word不为空值
if(str[i]>='A'&&str[i]<='Z')
str[i]+=32;
word+=str[i];
i++;
}
if(flag)
mp[word]++;
word.clear();
i++;
}
string a;int max=0;
for(map<string,int>::iterator i=mp.begin();i!=mp.end();i++)
{
// cout<<i->first<<" "<<i->second<<endl;
if(max<i->second)
{
max=i->second;
a=i->first;
}
}
cout<<a<<" "<<max<<endl;
return 0;
}
主要在于判断空值,添加一个flag可以解决问题