题干
C++实现
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<map>
using namespace std;
int main() {
char arr[200] = { 0 };
fgets(arr, 200, stdin);
int i = 0;
int alphaCount = 0;
bool isSpace = true;
int wordCount = 0;
map<char, int> alphaMap;
while (true) {
if (arr[i] == '\0' || arr[i] == '\n') {
break;
}
else if (arr[i] == ' ') {
isSpace = true;
}
else {
++alphaCount;
if (isSpace) {
wordCount++;
}
if (arr[i] >= 'A' && arr[i] <= 'Z') {
arr[i] += 32;
}
++alphaMap[arr[i]];
isSpace = false;
}
i++;
}
printf("%d\n", alphaCount);
printf("%d\n", wordCount);
map<char, int>::iterator it;
int maxTimes = 0;
for (it = alphaMap.begin(); it != alphaMap.end(); it++)
{
if (it->second > maxTimes) {
maxTimes = it->second;
}
}
for (it = alphaMap.begin(); it != alphaMap.end(); it++)
{
if (it->second == maxTimes) {
printf("%c ", it->first);
}
}
printf("\n");
printf("%d\n",maxTimes);
return 0;
}