? ? ? 化 竞 教 练 搓 石 点 名 反 扣 工 资
(゜ v゜ )つ 炉 炉 炉 石 石 石 大 大 大 佬 佬 佬 の の の 那 那 那 些 些 些 事 事 事
1. T R I E 树 1.\mathbb{TRIE}树 1.TRIE树
#include<bits/stdc++.h>
using namespace std;
int n, m, ans;
char c[55];
const int MAXN = 1e6 + 10;
struct Trie{
int next[27];
int cnt;
}trie[MAXN];
int tot = 1;
inline void insert(char *c){
int len = strlen(c + 1), now = 1;
for(int i = 1; i <= len; ++i){
if(!trie[now].next[c[i] - 'a']) trie[now].next[c[i] - 'a'] = ++tot;
now = trie[now].next[c[i] - 'a'];
}
}
inline int query(char *c){
int len = strlen(c + 1), now = 1;
for(int i = 1; i <= len; ++i){
if(!trie[now].next[c[i] - 'a']) return false;
now = trie[now].next[c[i] - 'a'];
}
trie[now].cnt++;
return trie[now].cnt;
}
int main(){
scanf("%d", &n);
while(n--){
scanf("%s", &c);
insert(c);
}
scanf("%d", &m);
while(m--){
scanf("%s", &c);
ans = query(c);
if(ans == 0) printf("WRONG\n");
if(ans == 1) printf("OK\n");
if(ans >= 2) printf("REPEAT\n");
}
return 0;
}
2. 精 短 简 练 の m a p 风 2.精短简练の\mathrm{map}风 2.精短简练のmap风
#include<bits/stdc++.h>
using namespace std;
map<string, int> a;
string s;
int n, m;
int main(){
cin >> n;
while(n--){
cin >> s;
a[s] = 1;
}
cin >> m;
while(m--){
cin >> s;
if(a[s] == 1){
puts("OK");
a[s] = 2;
}
else if(a[s] == 2) puts("REPEAT");
else puts("WRONG");
}
return 0;
}