0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P2580 于是他错误的点名开始了

R57927454
This commit is contained in:
Baoshuo Ren 2021-09-12 21:11:20 +08:00 committed by Baoshuo Ren
parent a3d3035bcb
commit 86b2891eb0
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -3,66 +3,26 @@
using namespace std;
int n, m;
map<string, int> m1, m2;
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++) {
while (n--) {
cin >> s;
insert(root, s, 0);
m1[s]++;
}
cin >> m;
for (int i = 0; i < m; i++) {
while (m--) {
cin >> s;
switch (query(root, s)) {
case 0:
cout << "WRONG" << endl;
break;
case 1:
cout << "OK" << endl;
break;
case 2:
cout << "REPEAT" << endl;
break;
m2[s]++;
if (m2[s] > 1) {
cout << "REPEAT" << endl;
} else if (m1[s]) {
cout << "OK" << endl;
} else {
cout << "WRONG" << endl;
}
insert(root, s, 1);
}
delete root;
return 0;
}