样例不过求调教,悬棺
查看原帖
样例不过求调教,悬棺
754673
Jackson_Miller楼主2023/8/9 10:06
#include<bits/stdc++.h>
using namespace std;
int trie[4*10005][66],sum[4*10005],tot;
char s[5001];
bool wz[4*10005][22];
int t,k;
int getchar(char x){
	if('a'<=x && x<='z') return x-'a';
	if('A'<=x && x<='Z') return x-'A'+26;
	else return x-'0'+52;
}
void insert(int x){
	int len=strlen(s);
	int root=0;
	for(int i=0;i<len;i++){
		int id=getchar(s[i]);
		if(!trie[root][id]){
			trie[root][id]=++tot;
		}
		root=trie[root][id];
	}
	wz[root][x]=1;
}
int sch(){
	int len=strlen(s);
	int root=0;
	int f=1;
	for(int i=0;i<len;i++){
		int id=getchar(s[i]);
		if(!trie[root][id]){
			f=0;
			break;
		}
		root=trie[root][id];
	}
	if(f){
		for(int i=1;i<=k;i++){
			if(wz[root][i]){
				cout<<i<<" ";
			}
		}
	}
	cout<<endl;
}
int main(){
	cin>>t;
	k=t;
	while(t--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>s;
			insert(i);
		}
	}
	cin>>t;
	while(t--){
		cin>>s;
		sch();
	}
}
2023/8/9 10:06
加载中...