蒟蒻求助救救孩子
查看原帖
蒟蒻求助救救孩子
447334
hahaboluo楼主2022/7/20 16:45

只有30分呜呜

#include<bits/stdc++.h>
using namespace std;
int n,m,idx,son[55][27];
bool st[500050];
char str[66];
void insert(char *str)
{
    int p=0;
    for(int i=0;str[i];i++)
    {
        int u=str[i]-'a';
        if(!son[p][u])  son[p][u]=++idx;
        p=son[p][u];
    }
}
int query(char *str)
{
    int p=0;
    for(int i=0;str[i];i++)
    {
        int u=str[i]-'a';
        if(!son[p][u])  return 0;
        p=son[p][u];
    }
    if(!st[p])
    {
        st[p]=true;
        return 2;
    }
    else
        return 1;
}
int main()
{
    cin>>n;
    while(n--)
    {   
        cin>>str;
        insert(str);
    }
    
    cin>>m;
    while(m--)
    {
        cin>>str;
        int k=query(str);
        if(k==0)
            cout<<"WRONG"<<endl;
        else if(k==1)
            cout<<"REPEAT"<<endl;
        else if(k==2)
            cout<<"OK"<<endl;
    }
    return 0;
}
2022/7/20 16:45
加载中...