C++求字符串最长连续字符的长度
#include<assert.h> int get_max_char_count(char *s,char *ret) { assert(s!=NULL); char *temp_char,*final_char,*p; int temp_count,final_count=0; p=s; while(*p!='\0') { temp_count=0; for(temp_char=p,p=p+1,temp_count=1;*p!='\0';p++) { if(*p==*temp_char) temp_count++; else break; } if(temp_count>final_count) { final_char=temp_char; final_count=temp_count; } } *ret=*final_char; return final_count; } void main() { char s[]="aabbbcccc"; int count; char c; count=get_max_char_count(s,&c); printf("%c is appeared %d times\n",c,count); }