Trie树30分,求调
  • 板块灌水区
  • 楼主Wrx1011
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/8 21:50
  • 上次更新2024/8/9 07:07:47
查看原帖
Trie树30分,求调
1054957
Wrx1011楼主2024/8/8 21:50

P2580,Rt,请求dalao

#include <bits/stdc++.h>
using namespace std;
int trie[100010][30],tot=1,t[100010],t_=0;
inline void insert(string s){
	int len=s.length(),rt=1;
	for(int i=0;i<len;i++){
		int c=s[i]-'a';
		if(!trie[rt][c]){
			trie[rt][c]=++tot;
		}
		rt=trie[rt][c];
	}
	t[rt]=1;
}
inline int find(string s){
	int len=s.length(),rt=1;
	for(int i=0;i<len;i++){
		int c=s[i]-'a';
		if(trie[rt][c]==0){
			return 0;
		}
		rt=trie[rt][c];
	}
	t_=rt;
	return t[t_];
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int x,h;
	string xh;
	cin>>x;
	for(int i=0;i<x;i++){
		cin>>xh;
		insert(xh);
		xh.clear();
	}
	cin>>h;
	for(int i=0;i<h;i++){
		cin>>xh;
		if(find(xh)==1){
			cout<<"OK\n";
			t[t_]++;
		}else if(find(xh)>1){
			cout<<"REPEAT\n";
		}else{
			cout<<"WRONG\n";
		}
		xh.clear();
	}
	return 0;
}
2024/8/8 21:50
加载中...