Advertisement
MaskerQwQ

P2580 于是他错误的点名开始了

Mar 25th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. const int N=26;
  7.  
  8. struct trieNode{
  9.     int times=0;
  10.     char val;
  11.     trieNode** son;
  12.     int cnt;
  13.     trieNode(char c){
  14.         val=c;
  15.         son=new trieNode*[N];
  16.         for(int i=0;i<N;i++){
  17.             son[i]=0;
  18.         }
  19.         cnt=0;
  20.     }
  21. };
  22. trieNode* root;
  23.  
  24. void insert(string s){
  25.     trieNode* p=root;
  26.     for(int i=0;i<s.size();i++){
  27.         int c=s[i]-'a';
  28.         if(!p->son[c]){
  29.             p->son[c]=new trieNode(c);
  30.         }else{
  31.             p=p->son[c];
  32.         }
  33.     }
  34.     p->cnt++;      
  35. }
  36.  
  37. int query(string s){
  38.     trieNode*p=root;
  39.     for(int i=0;i<s.size();i++){
  40.         int c=s[i]-'a';
  41.         if(!p->son[c])return 0;
  42.         p=p->son[c];
  43.     }
  44.     if(!p->times){
  45.         p->times=1;return 1;
  46.     }else{
  47.         return 2;
  48.     }  
  49. }
  50. int main()
  51. {
  52.     root=new trieNode(' ');
  53.     int n, m;
  54.     cin>>n;
  55.     for(int i=1;i<=n;i++){
  56.         string s;
  57.         cin>>s;
  58.         insert(s);
  59.     }
  60.     cin>>m;
  61.     for(int j=1;j<=m;j++){
  62.         string s;
  63.         cin>>s;
  64.         if(query(s)==1){
  65.             cout<<"OK"<<endl;
  66.         }else{
  67.             if(query(s)==2){
  68.                 cout<<"REPEAT"<<endl;
  69.             }else{
  70.                 cout<<"WRONG"<<endl;
  71.             }
  72.         };
  73.     }
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement