Problem Description
输入英文句子,输出该句子中除了空格外出现次数最多的字符及其出现的次数。
Input
输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。
Output
逐行输出每个句子中出现次数最多的字符及其出现的次数(如果有多个字符的次数相同,只输出ASCII码最小的字符)。
Sample Input
I am a student
a good programming problem
ABCD abcd ABCD abcd
Sample Output
a 2
o 4
A 2
利用ASCII码比较容易。。。
#include <stdio.h> int main() {char s[100];int cnt[123];int max;while(gets(s)!=NULL){for(int k=65;k<=122;k++)cnt[k]=0;max=65;for(int i=0;s[i]!='\0';i++)if(s[i]!=' ')cnt[s[i]]++;for(int k=66;k<=122;k++)if(cnt[k]>cnt[max])max=k;printf("%c %d\n",max,cnt[max]);}return 0; }
123456789101112131415161718192021