0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-13 00:38:49 +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; using namespace std;
int n, m; int n, m;
map<string, int> m1, m2;
string s; 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() { int main() {
node* root = new node();
cin >> n; cin >> n;
for (int i = 0; i < n; i++) { while (n--) {
cin >> s; cin >> s;
insert(root, s, 0); m1[s]++;
} }
cin >> m; cin >> m;
for (int i = 0; i < m; i++) { while (m--) {
cin >> s; cin >> s;
switch (query(root, s)) { m2[s]++;
case 0: if (m2[s] > 1) {
cout << "WRONG" << endl; cout << "REPEAT" << endl;
break; } else if (m1[s]) {
case 1: cout << "OK" << endl;
cout << "OK" << endl; } else {
break; cout << "WRONG" << endl;
case 2:
cout << "REPEAT" << endl;
break;
} }
insert(root, s, 1);
} }
delete root;
return 0; return 0;
} }