代码有点长,不影响使用,如果有相同最大次数的字符出现,只显示第一个。
#include
int main(void)
{
char colum[128];
int count[128];
int i,j,k,maxium = 0,columsize = 0;
char c1,the_char;
for (i = 0; i < 128; i++)
{
colum[i] = 0;
count[i] = 0;
}
while((c1 = getchar()) != '\n')
{
if (colum[0] == 0)
{
colum[0] = c1;
columsize++;
}
for(j = 0; j < columsize; j++)
{
if ( c1 == colum[j])
{
count[j]++;
break;
}
if(columsize - j == 1)
{
colum[columsize] = c1;
columsize++;
}
}
}
for (k = 0; k < columsize; k++)
{
if (maxium < count[k])
{
maxium = count[k];
the_char = colum[k];
}
}
printf("the maxium char is %c,it appears %d\n",the_char,maxium);
return 0;
}
123213123213哈哈哈