用Hash写的,全部RE,求调(码风不佳,请勿见怪)
#include <bits/stdc++.h>
using namespace std;
char a[10000001];
unsigned long long m=1e9+7,p=131,nxt[10000001],tot=0,head[10000001],real_[10000001],num[10000001];
unsigned long long h[10000001];
inline void insert(unsigned long long x)
{
tot++;
nxt[tot]=head[x%m];
head[x%m]=tot;
real_[tot]=x;
num[tot]=0;
}
inline int search(unsigned long long x)
{
for(int i=head[x%m];i;i=nxt[i])
{
if(real_[i]==x&&num[i]==0)
{
num[i]=1;
return 1;
}
if(real_[i]==x&&num[i]==1)
return 2;
}
return 3;
}
int main()
{
int n,m;
cin>>n;
memset(h,1,sizeof(h));
for(int i=1;i<=n;i++)
{
cin>>a+1;
int len=strlen(a+1);
for(int j=1;j<=len;j++)
{
h[i]=h[i]*p+a[j];
}
insert(h[i]);
}
memset(h,1,sizeof(h));
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>a+1;
int len=strlen(a+1);
for(int j=1;j<=len;j++)
{
h[i]=h[i]*p+a[j];
}
int u=search(h[i]);
if(u==1)
cout<<"OK"<<endl;
if(u==2)
cout<<"REPEAT"<<endl;
if(u==3)
cout<<"WRONG"<<endl;
}
return 0;
}