字符统计2

来源:互联网 发布:mac系统截图快捷键 编辑:程序博客网 时间:2024/06/04 19:12

字符统计2

Problem Description


输入英文句子,输出该句子中除了空格外出现次数最多的字符及其出现的次数。


Input

输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。


Output
逐行输出每个句子中出现次数最多的字符及其出现的次数(如果有多个字符的次数相同,只输出ASCII码最小的字符)。
Example Input


I am a studenta good programming problemABCD abcd ABCD abcd

Example Output


a 2o 4A 2

代码:

#include <stdio.h>#include <string.h>int main(){    char s[200];    int a[200], i, len, max, k;    while(gets(s))    {        len = strlen(s);        k = max = 0;        memset(a, 0, sizeof(a));        for(i = 0; i < len; i++)        {            if(s[i] == ' ')            {                continue;            }            a[s[i]]++;        }        for(i = 0; i < 200; i++)        {            if(max < a[i])            {                max = a[i];                k = i;            }        }        printf("%c %d\n", k, max);    }    return 0;}