您的位置:首页 > 其它

统计一字符串中个数最多的字符

2015-09-08 22:40 211 查看
#include"stdio.h"

#include"string.h"

//找出个数最多的字符
main(){
char str[50],*p1,*p2,*max_p;
int count=0,maxcount=0;
gets(str);
p1=str;

for(p1;*p1!='\0';p1++){
count=0;
for(p2=p1;*p2!='\0';p2++){
if(*p1==*p2){
count++;
}
}
if(count>maxcount){
maxcount=count;
max_p=p1;
}
}
printf("%c %d\n",*max_p,maxcount);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: