比较两个字符串最长有多少个连续字符相等

比较两个字符串最长有多少个连续字符相等

#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;
}

posted on 2023-05-31 20:48  wessf  阅读(18)  评论(0)    收藏  举报