比较两个字符串最长有多少个连续字符相等
#include <stdio.h>
#include <string.h>
int compare(char* a,char* b)
{
int i,j;
int len=0;
int max=0;
int temp=0;
for(i=0;i<strlen(a);i=temp,i++)
{
temp=i;
for(j=0,len=0;j<strlen(b);j++)
{
while(a[i]==b[j]&&a[i]!='\0'&&b[j]!='\0')
{
len++;
i++;
j++;
max=max>len?max:len;
}
}
}
return max;
}
int main()
{
char a[128]="abcdefgddd";
char b[128]="ooooabcdefgdd";
printf("%d\n",compare(a,b));
return 0;
}
标签:字符,compare,相等,int,max,char,字符串
From: https://www.cnblogs.com/yesiming/p/17447278.html