#include <iostream>//找好几个字符串的最长公共后缀
#include <string>
#include <algorithm>
using namespace std;
int main(){
int n;
char s[500];
string next,suffix;
// freopen("/Users/pantingting/Documents/code/data/input", "r", stdin);
scanf("%d",&n);
getchar();//读掉后面的换行符,否则下面的gets读不进来
gets(s);
suffix=string(s);
reverse(suffix.begin(), suffix.end());
for (int i=1; i<n; i++) {
gets(s);
next=string(s);
reverse(next.begin(), next.end());
int idx=0;
for (; idx<next.length()&&idx<suffix.length(); idx++) {
if (suffix[idx]!=next[idx]) {
break;
}
}
suffix=suffix.substr(0,idx);
}
if (suffix.length()>0) {
reverse(suffix.begin(), suffix.end());
printf("%s\n",suffix.c_str());
}
else
printf("nai\n");
return 0;
}
PAT1077
最新推荐文章于 2024-06-20 21:06:44 发布