30pts re求调
查看原帖
30pts re求调
803851
hualuo_2楼主2024/7/15 15:29
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	 } 
	while(ch>='0'&&ch<='9')  x=x*10+(ch^48),ch=getchar();
	return x*f;
}

const int mn=1e6+10;
int n,m,ch[5005][26],tag[mn],tot=1;
char s[mn];

void insert()
{
	int u=1;
	for(int j=1;s[j];++j)
	{
		int c=s[j]-'a';
		if(!ch[u][c]) ch[u][c]=++tot;
		u=ch[u][c];
	}
	tag[u]=1;
}

void find()
{
    int u=1; 	
    for(int j=1;s[j];++j)
    {
    	int c=s[j]-'a';
    	u=ch[u][c];
		if(!u) break; 
	}
	if(tag[u]==1)
	{
		printf("OK\n");
		tag[u]=2;
	}
	else if(tag[u]==2) printf("REPEAT\n");
	else printf("WRONG\n");
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		insert();
	}
	m=read();
	for(int i=1;i<=m;i++)
	{
		scanf("%s",s+1);
		find();
	}
	return 0;
}
2024/7/15 15:29
加载中...