给定两个字符串,求出它们之间最长的相同子字符串的长度。

#include
#include
#include

void main()
{线程之间共享数据的方式
char *s1 = “woaibeijingtiananmen”;
char *s2 = “welcometobeijing”;
int count[50] = { 0 };
int i = 0;
int k = 0;
int max = 0;
int m = 0;
char *ps[50] = { 0 };
for (char *pc1 = s1; *pc1 != ‘\0’; pc1++){
for (char *pc2 = s2; *pc2 != ‘\0’; pc2++){
char *temp1 = pc1;
char *temp2 = pc2;
if ((*temp1 == *temp2) && (*temp2 != ‘\0’)){
ps[i] = temp1; //保留地址
while ((*temp1 == *temp2) && (*temp2 != ‘\0’)){
temp1++;
temp2++;
count[i]++;
}
i++;
}
}
}

for (int i = 0; i < 50; i++){
//printf("%d\n", count[i]);
if (max < count[i]){
k = i;
max = count[i];
}
}
printf(“字符串子串最大长度:%d\n”, max);
printf(“该子串为:”);
/*for (int i = k;m {
printf(" %c “, ps[i]);
ps[i]++;
m++;
}
/
while (m < max){
printf(”%c", *ps[k]);
ps[k]++;
m++;
}
printf("\n");
system(“pause”);
}

你可能感兴趣的:(编程题)