0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 17:56:28 +00:00

P2580 于是他错误的点名开始了 [80' Code]

R57926576
This commit is contained in:
Baoshuo Ren 2021-09-12 21:09:03 +08:00 committed by Baoshuo Ren
parent 88667928c4
commit a3d3035bcb
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,68 @@
#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
struct node {
bool flag[2];
node* next[26];
~node() {
for (auto& i : next) {
delete i;
}
}
};
void insert(node* root, string s, bool type) {
node* p = root;
while (!s.empty()) {
if (p->next[s[0] - 'a'] == nullptr) {
p->next[s[0] - 'a'] = new node();
}
p = p->next[s[0] - 'a'];
s = s.substr(1);
}
p->flag[type] = true;
}
inline int query(node* root, string s) {
node* p = root;
while (!s.empty()) {
if (p->next[s[0] - 'a'] == nullptr) {
return 0;
}
p = p->next[s[0] - 'a'];
s = s.substr(1);
}
return p->flag[1] ? 2 : 1;
}
int main() {
node* root = new node();
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
insert(root, s, 0);
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> s;
switch (query(root, s)) {
case 0:
cout << "WRONG" << endl;
break;
case 1:
cout << "OK" << endl;
break;
case 2:
cout << "REPEAT" << endl;
break;
}
insert(root, s, 1);
}
delete root;
return 0;
}