题目描述
分析:使用map记录每个字符串出现的次数即可
C++ isalpha、isalnum、islower、isupper用法
#include<map>
#include<iostream>
#include<string>
using namespace std;
int main(){
map<string,int> mp;
string str,temp="";
getline(cin,str);
for(int i=0;i<str.size();i++){
if(isalnum(str[i])){
temp+=tolower(str[i]);
}
else if(temp.length()>0){
++mp[temp];
temp="";
}
}
if(!temp.empty()){
mp[temp]++;
}
auto index=mp.cbegin();
for(auto i=mp.cbegin();i!=mp.cend();i++){
if(i->second>index->second){
index=i;
}
}
cout<<index->first<<" "<<index->second<<endl;
return 0;
}