Code
#include <stdio.h>
#include <string.h>
int main()
{
char s[101];
int cnt[101];
int i,j,k,max;
while(gets(s) != NULL)
{
memset(cnt,0,sizeof(cnt));
k = max = 0;
int len = strlen(s);
for(i=0; i<len-1; i++)
{
if(s[i] != ' ')
{
cnt[s[i]]++;
}
}
for(i=0; i<101; i++)
{
if(max < cnt[i])
{
max = cnt[i];
k = i;
}
}
printf("%c %d\n",k,max);
}
return 0;
}
反思:字符串练习题,主要思路是用一个cnt数组储存除空格外每个字符出现的次数,用k储存出现次数最多的字符。字符在cnt数组内的储存形式为ASCII码。