题目描述
给出若干个字符串,输出这些字符串的最长公共后缀。
样例
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
while(cin>>n,n!=0){
string s1;
cin>>s1;
if(n==1){
cout<<s1<<endl;
continue;
}
int c=0;
for(int i=0;i<n-1;i++){
string s2;
cin>>s2;
if(s2.size()<s1.size()){
string temp=s2;
s2=s1;
s1=temp;
}
int len=s1.size();
for(int j=0;j<s2.size();j++){
if(s2.substr(s2.size()-s1.size()+j)==s1.substr(j)){
s1=s1.substr(j,len);
c++;
break;
}
}
}
if(c==n-1)cout<<s1<<endl;
else cout<<""<<endl;
}
return 0;
}