#include<cstdio>
#include <cctype>
#include <string>
using namespace std;
int main() {
string s;
getline(cin, s);
int a[26] = {0};
for (int i = 0; i < s.length(); i++)
s[i] = tolower(s[i]);
for (int i = 0; i < s.length(); i++)
if (islower(s[i])) a[s[i] - 'a']++;
int max = a[0], t = 0;
for (int i = 1; i < 26; i++) {
if (a[i] > max) {
max = a[i];
t = i;
}
}
printf("%c %d", t + 'a', max);
return 0;
}
发现:用string一些本身自带的函数代码会变得很简短。
B1042 字符统计
最新推荐文章于 2020-12-10 17:57:45 发布