点击打开链接
//暴力+find()
#include <iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int maxr=4000+5;
const int maxc=200+5;
vector<string>str;
char ss[maxr][maxc];
int main()
{
int n;
while(scanf("%d",&n)==1&&n)
{
for(int i=0;i<n;i++)
scanf("%s",&ss[i]);
string b;
b.clear();
b=ss[0];
//以0串作为模式串进行匹配
int t=b.length();
for(int i=0;i<t;i++) //起始位置
{
string k;
k.clear();
k=b.substr(i);
for(int len=1;i+len<=t;len++) //左闭右开
{
string f;
f.clear();
f=k.substr(0,len);
//next数组取0-len长度
bool flag=true;
for(int x=1;x<n;x++)
{
string f1;
f1.clear();
f1=ss[x];
if(f1.find(f)==string::npos) {
flag=false;
break;
}
}
if(flag) {
if(!str.size()) {
str.push_back(f);
}
else {
int m=f.length();
if(m<str[0].length()) continue;
if(m>str[0].length()) str.clear();
str.push_back(f);
}
}
}
}
if(!str.size()) printf("IDENTITY LOST\n");
else {
sort(str.begin(),str.end());
cout<<str[0]<<endl;
}
str.clear();
}
return 0;
}
hdu 2328 暴力枚举+find()
最新推荐文章于 2021-07-20 09:44:33 发布