只支持C++14且厌氧的神奇代码
查看原帖
只支持C++14且厌氧的神奇代码
682196
2022dyxwitHLove楼主2024/8/3 09:55
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, idx;
string a;
struct Node{
	int son[100];
	bool flg;
	bool vis;
}node[N];
void insert(int x, int y) {
	if (y == a.length()) {
		node[x].flg = true;
		return;
	}
	if (node[x].son[a[y] - 'a']) insert(node[x].son[a[y] - 'a'], y + 1);
	else {
		node[x].son[a[y] - 'a'] = ++idx;
		insert(idx, y + 1);
	}
}
int find(int x, int y) {
	if (y == a.length()) {
		if (node[x].flg == true) {
			if (node[x].vis) return 1;
			node[x].vis = true;
			return 0;
		}
		else return 2;
	} 
	if (!node[x].son[a[y] - 'a']) return 2;
	find(node[x].son[a[y] - 'a'], y + 1);
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		insert(1, 0);
	}
	cin >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> a;
		int s = find(1, 0);
		if (s == 0) cout << "OK" << '\n';
		if (s == 1) cout << "REPEAT" << '\n';
		if (s == 2) cout << "WRONG" << '\n';
	}
}
2024/8/3 09:55
加载中...