AcWing 3303. 单词分析(字符串)
原题链接
简单
作者:
xrzscxy
,
2021-04-02 16:54:22
,
所有人可见
,
阅读 473
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <unordered_map>
using namespace std;
string s;
unordered_map <char,int> res;
int main(){
getline(cin,s);
for(int i = 0;i < s.length();i++){
char t;
t = s[i];
res[t]++;
}
int max = 0;
char flag;
for(auto r:res){
if(r.second > max){
max = r.second;
flag = r.first;
}
else if(r.second == max){
if(r.first < flag)flag = r.first;
}
}
cout << flag << endl;
cout << max << endl;
return 0;
}