题目链接:点击打开链接
知识点笔记:
这题的关键是字符串的反置,也可以用reverse函数做
AC代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
int n,minLen=256,count=0;
char s[100][256];
scanf("%d",&n);
getchar();//接收换行符
for(int i=0;i<n;i++){
gets(s[i]);
int len = strlen(s[i]);
minLen = min(minLen,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<minLen;i++){
char c = s[0][i];
bool same = true;
for(int j=1;j<n;j++){
if(c!=s[j][i]){
same = false;
break;
}
}
if(same) count++;
else break;
}
if(count){
for(int i=count-1;i>=0;i--){
printf("%c",s[0][i]);
}
}else{
printf("nai");
}
return 0;
}