···
include<iostream>
include <stdio.h>
include <string.h>
using namespace std;
int main()
{
int cases, sum[26], i, max;
char str[1001];
cin >> cases;
while (cases > 0) {
cin >> str;
for (i = 0; i < 26; i++) {//每次都赋出现次数初值0
sum[i] = 0;
}
for (i = 0; i < strlen(str); i++) {//记各个数字出现次数
sum[str[i] - 'a']++;
}
max = 0;
for (i = 0; i < 26; i++) {
if (sum[i] > sum[max])max = i;//找出最大的
}
cout <<char( max + 'a') << " " << sum[max] << endl;//根据下标找到
cases--;
}
system("pause");
}
···
网友评论