AcWing 779. 最长公共字符串后缀
原题链接
困难
作者:
AntKing
,
2021-05-24 00:35:33
,
所有人可见
,
阅读 199
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main ()
{
int n;
while(scanf("%d",&n)&&n!=0)
{
map<string,int> smap;
int maxn=0,tmp=0,cnt=0,flag=0;
string s[25000],t;
for(int i=0;i<n;i++)
{
cin>>s[i];
for(int j=0;j<s[i].size();j++)
{
smap[s[i].substr(j)]++;
if(smap[s[i].substr(j)]>maxn)
{
maxn=smap[s[i].substr(j)];
t=s[i].substr(j);
if(i>0){cnt=1;}
}
}
if(i>0&&(s[i].substr(s[i].size()-1)!=s[i-1].substr(s[i-1].size()-1)))
{
flag=1;
}
}
if(cnt==0||flag==1)
{
cout<<"\n";
}else{
cout<<t<<"\n";
}
}
}