#include<stdio.h>
#include<string.h>
char * FindCommon(char a[], char b[]){
int len1 = strlen(a), len2 = strlen(b);
int i = len1 - 1, j = len2 - 1;
int flag = 0;
for (; i >= 0 && j >= 0; i--, j--)
if (a[i] != b[j]){
flag = 1;
break;
}
if (flag)
strcpy(b, &a[i + 1]);
else if (len1 <= len2)
strcpy(b, a);
else strcpy(b, &a[len1 - len2]);
return b;
}
int main(){
char CommonSuf[260], str[260];
int n;
freopen("1.in", "r", stdin);
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i++)
{
//scanf("%s", &str);
//getchar();
gets(str);
if (i == 0)
strcpy(CommonSuf, str);
else strcpy(CommonSuf,FindCommon(str, CommonSuf));
}
if (strlen(CommonSuf))
printf("%s\n", CommonSuf);
else printf("nai\n");
return 0;
}
pat 1077
最新推荐文章于 2021-11-20 10:03:05 发布