RE求助
查看原帖
RE求助
528287
多喝岩浆楼主2022/2/13 10:25
#include<bits/stdc++.h>

using namespace std;
const int N = 5e5 + 10;
int n, m;
char tree[N][28];
int tot = 1;
int flag[N];
void jointree (string st) {
	int dep = 1;
	for (int i = 0, len = st.size (); i < len; i++) {
		int ch = st[i] - 'a' + 1;
		if (tree[dep][ch] == 0) tree[dep][ch] = ++tot;
		dep = tree[dep][ch];
	}
	flag[dep] = 1;
} 
int findtree (string st) {
	int dep = 1;
	for (int i = 0, len = st.size (); i < len; i++) {
		int ch = st[i] - 'a' + 1;
		if (tree[dep][ch] == 0) return 0;
		dep = tree[dep][ch];
	}
	if (flag[dep] == 2) return 2;
	flag[dep] = 2;
	return 1;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string st;
		cin >> st;
		jointree (st); 
	}	
	cin >> m;
	for (int i = 1; i <= m; i++) {
		string st;
		cin >> st;
		int x = findtree (st);
		if (x == 0) cout << "WRONG" << endl;
		if (x == 1) cout << "OK" << endl;
		if (x == 2) cout << "REPEAT" << endl;
	}
    return 0;	
}
2022/2/13 10:25
加载中...