玄关
查看原帖
玄关
237650
Crouy_Li_Dorac楼主2024/8/6 15:19

求助,字典树hack数据WA,玄关

#include<bits/stdc++.h>
const int N=1e7+10;
using namespace std;
int tree[N][26];
bool cnt[N];
int idx=1;
int n,m;
string s;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>s;
		int p=1;
		for(int i=0;s[i];i++){
			int key=s[i]-'a';
			if(!tree[p][key]){
				tree[p][key]=idx;
				idx++;
			}
			p=tree[p][key];
		}
		cnt[p]=true;
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		cin>>s;
		int p=1;
		for(int i=0;s[i];i++){
			int key=s[i]-'a';
			if(!tree[p][key]){
				puts("WRONG");
				goto end; 
			}
			p=tree[p][key];
		}
		if(cnt[p]){
			puts("OK");
			cnt[p]=false;
		}
		else
			puts("REPEAT");
		end:continue;
	}
	return 0;
}
2024/8/6 15:19
加载中...