直接用字典树维护即可,不过这个题其实直接用map也能过…
字典树:
// Created by CAD
#include <bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
struct trie{
int nex[maxn][26],cnt=0;
bool exist[maxn];
void insert(string s){
int slen=s.length(),p=0;
for(int i=0;i<slen;++i){
int c=s[i]-'a';
if(!nex[p][c]) nex[p][c]=++cnt;
p=nex[p][c];
}
exist[p]=1;
}
bool find(string s){
int slen=s.length(),p=0;
for(int i=0;i<slen;++i){
int c=s[i]-'a';
if(!nex[p][c]) return 0;
p=nex[p][c];
}
return exist[p];
}
};
trie tr,vis;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for(int i=1;i<=n;++i){
string s;cin>>s;
tr.insert(s);
}
int m;cin>>m;
for(int i=1;i<=m;++i){
string s;cin>>s;
if(vis.find(s)) cout<<"REPEAT"<<endl;
else{
if(tr.find(s)) cout<<"OK"<<endl,vis.insert(s);
else cout<<"WRONG"<<endl;
}
}
return 0;
}
map:
// Created by CAD
#include <bits/stdc++.h>
using namespace std;
map<string,bool> exist,vis;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
for(int i=1;i<=n;++i){
string s;cin>>s;
exist[s]=1;
}
int m;cin>>m;
for(int i=1;i<=m;++i){
string s;cin>>s;
if(vis[s]) cout<<"REPEAT"<<endl;
else{
if(exist[s]) cout<<"OK"<<endl,vis[s]=1;
else cout<<"WRONG"<<endl;
}
}
return 0;
}