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

点击查看代码
#include<bits/stdc++.h>
using namespace std;

const int N=5e5+10;
int tr[N][26],tag[N],idx;
int n,m;

void insert(const string& s)
{
    int p=0;
    for(char c : s){
        int u=c-'a';
        if(!tr[p][u]) tr[p][u]=++idx;
        p=tr[p][u];
    }
    tag[p]=1;
}

int query(const string& s)
{
    int p=0;
    for(char c:s){
        int u=c-'a';
        if(!tr[p][u]) return 0;
        p=tr[p][u];
    }

    if(tag[p]==1){
        tag[p]=2;
        return 1;
    }else if(tag[p]==2){
        return 2;
    }else return 0;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        insert(s);
    }
    cin>>m;
    while(m--){
        string s;
        cin>>s;
        int ans=query(s);
        if(ans==1){
            cout<<"OK"<<"\n";
        }else if(ans==2){
            cout<<"REPEAT"<<"\n";
        }else{
            cout<<"WRONG"<<"\n";
        }
    }

    return 0;
}
posted @ 2026-03-02 21:42  AnoSky  阅读(0)  评论(0)    收藏  举报