#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lowbit(x) ((x)&(-x))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using pll=pair<ll,ll>;
const int MAXN=1e6+5;
const int INF=0x3f3f3f3f;
const ll NNF=0x3f3f3f3f3f3f3f3f;
int n;
int tri[MAXN][26],cnt;
bool exist[MAXN],vis[MAXN];
void init(){
memset(tri,0,sizeof(tri));
cnt=1;
}
void insert(const string &s){
int cur=1;
for(auto c:s){
if(!tri[cur][c-'a']) tri[cur][c-'a']=++cnt;
cur=tri[cur][c-'a'];
}
exist[cur]=1;
}
void find_prefix(const string &s){
int cur=1;
for(auto c:s){
if(!tri[cur][c-'a']) return void(printf("WRONG\n"));
cur=tri[cur][c-'a'];
}
if(!exist[cur]) printf("WRONG\n");
else if(!vis[cur]){
printf("OK\n");
vis[cur]=1;
}
else printf("REPEAT\n");
}
void solve(){
init();
scanf("%d",&n);
string s;
for(int i=1;i<=n;i++){
cin>>s;
insert(s);
}
scanf("%d",&n);
for(int i=1;i<=n;i++){
// scanf("%d",&n);
cin>>s;
find_prefix(s);
}
}
int main(){
solve();
return 0;
}
字典树(随学)
最新推荐文章于 2024-09-03 18:29:17 发布