#import <Foundation/Foundation.h>
#import "stdio.h"
#import "string.h"
int main() {
char str1[110] = "";
char str2[110] = "";
char str3[110] = "";
// char str4[100][100] ;
printf("请输入两行字符串\n");
gets(str1);
gets(str2);
int k = 0, l = 0;
int flag = 0;
// int num = 0;
for (int i = 0;str1[i] != '\0';i++ ) {// str1遍历
for (int j = 0; str2[j] != '\0';j++ ) {// str2遍历
while ((str1[i] == str2[j]&& str1[i + l] == str2[j + l] && str1[i + l] != '\0' )) {// 找到了首个相等的字母,&&上下一个字母,完成了连接.
str3[k] = str1[i + l];
l++;
k++;
// printf("%s\n",str3);
if (str1[i + l] != str2[j + l] && str1[i + l] != '\0') {
flag = 1;
}
}
if (flag == 1) {
l = 0;
//strcpy(str4[num], str3);
//num++;
// printf("%s\n",str4[num]);
flag = 0;
k = 0;
}
}
}
printf("%s\n",str3);
return 0;
} |
|