字母统计(241)

描述现在给你一个由小写字母组成字符串,要你找出字符串中出现次数最多的字母,如果出现次数最多字母有多个那么输出最小的那个。

 

#include<stdio.h>
#include<string.h>
int main()
{
char str[1010];
int n, len, i, max, j;
scanf("%d",&n);
    while(n--)
    {
        int    a[26] = {0};
        max = 0;
        j = 0;
        scanf("%s",str);
        len = strlen(str);
        for(i = 0; i < len; i++)
        {
            a[str[i]-'a']++;
        }
        for(i = 0; i < 26; i++)
        if(max < a[i])
        {
             j = i;
            max = a[i];
        }
         printf("%c\n", j + 'a');
    }
 return 0;
}

 

posted @ 2014-10-09 14:51  静以养身 俭以养德  阅读(118)  评论(0编辑  收藏  举报