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

来源:互联网 发布:移动网络的账号和密码 编辑:程序博客网 时间:2024/05/18 01:24
#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);}

0 0
原创粉丝点击