lg2580[板子]

链接:lg2580[板子]

题解

  • Trie树板子
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #define rep(i,x,y) for(register int i=x;i<=y;++i)
    #define repd(i,x,y) for(register int i=x;i>=y;--i)
    #define ll long long
    using namespace std;
    const int N=1e6+7;
    int tr[N][26],end[N],cnt,n,m,x;
    char a[N];
    inline void add(char* str){
    int len=strlen(str)-1,p=1;
    rep(i,0,len){
    int k=str[i]-'a';
    if(!tr[p][k])tr[p][k]=++cnt;
    p=tr[p][k];
    }
    end[p]=1;
    }
    inline int query(char* str){
    int len=strlen(str)-1,p=1;
    rep(i,0,len){
    p=tr[p][str[i]-'a'];
    if(p==0)return 0;
    }
    return end[p]++;
    }
    int main(){
    scanf("%d",&n);
    rep(i,1,n){scanf("%s",a);add(a);}
    scanf("%d",&m);
    rep(i,1,m){
    scanf("%s",a);int t=query(a);
    if(t==1){puts("OK");}
    else if(t>1)puts("REPEAT");
    else puts("WRONG");
    }
    return 0;
    }