C语言统计字符串中出现次数最多的字符及对应的个数
#include <stdio.h> #include <string.h> int main(){ char cs[1024]; gets(cs); int count[256] = {0},i,m; for(i=0; i<strlen(cs); i++) count[cs[i]]++; int max = 0; char c = 0; for(i=0; i<256; i++){ if(count[i] > max){ max = count[i]; c = (char)i;m=i; } } printf("出现次数:%d\n",count[m]); for(i=0;i<256;i++) if(count[i]==count[m]) printf("%c ",(char)i); getchar(); }