题目:https://www.patest.cn/contests/pat-a-practise/1077
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
int n,min=300,pos=0;
char s[105][270];
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++){
gets(s[i]);
int len=strlen(s[i]);
if(len<min)
min=len;
for(int j=0;j<len/2;j++){
char temp=s[i][j];
s[i][j]=s[i][len-j-1];
s[i][len-j-1]=temp;
}
}
for(int i=0;i<min;i++){
char tem=s[0][i];
bool flag=true;
for(int j=1;j<n;j++){
if(tem!=s[j][i]){
flag=false;
break;
}
}
if(flag) pos++;
else break;
}
if(pos){
for(int i=pos-1;i>=0;i--){
printf("%c",s[0][i]);
}
}else{
printf("nai");
}
system("pause");
}