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