编写函数int search(char *cpSource,char ch),该函数在一个字符串cpSource(长度不超过100)中找到可能的最长的子字符串,该字符串是由同一字符组成的。
输入用例:ffbbeeddddeeeeeffffff
e
输出用例:eeeee
//查找最长的重复子串
#include<stdio.h>
#include<string.h>
int search(char *cpSource,char ch){
int max=0,count=0;
for(int i=0;i<=strlen(cpSource);i++){
if(cpSource[i]==ch){
count++;
}
else{
if(count>max)
max=count;
count=0;
}
}
return max;
}
int main(){
char str[99],ch;
gets(str);
ch=getchar();
int max=search(str,ch);
for(int i=0;i<max;i++)
putchar(ch);
return 0;
}