Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int N=26;
- struct trieNode{
- int times=0;
- char val;
- trieNode** son;
- int cnt;
- trieNode(char c){
- val=c;
- son=new trieNode*[N];
- for(int i=0;i<N;i++){
- son[i]=0;
- }
- cnt=0;
- }
- };
- trieNode* root;
- void insert(string s){
- trieNode* p=root;
- for(int i=0;i<s.size();i++){
- int c=s[i]-'a';
- if(!p->son[c]){
- p->son[c]=new trieNode(c);
- }else{
- p=p->son[c];
- }
- }
- p->cnt++;
- }
- int query(string s){
- trieNode*p=root;
- for(int i=0;i<s.size();i++){
- int c=s[i]-'a';
- if(!p->son[c])return 0;
- p=p->son[c];
- }
- if(!p->times){
- p->times=1;return 1;
- }else{
- return 2;
- }
- }
- int main()
- {
- root=new trieNode(' ');
- int n, m;
- cin>>n;
- for(int i=1;i<=n;i++){
- string s;
- cin>>s;
- insert(s);
- }
- cin>>m;
- for(int j=1;j<=m;j++){
- string s;
- cin>>s;
- if(query(s)==1){
- cout<<"OK"<<endl;
- }else{
- if(query(s)==2){
- cout<<"REPEAT"<<endl;
- }else{
- cout<<"WRONG"<<endl;
- }
- };
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement