structTRIE { int nex[100000][26], cnt; bool exist[100000]; // 该结点结尾的字符串是否存在
voidinsert(char* s, int l)// 插入字符串 { int p = 0; for (int i = 0; i < l; i++) { int c = s[i] - 'a'; if (!nex[p][c]) nex[p][c] = ++cnt; // 如果没有,就添加结点 p = nex[p][c]; } exist[p] = 1; } boolfind(char* s, int l)// 查找字符串 { int p = 0; for (int i = 0; i < l; i++) { int c = s[i] - 'a'; if (!nex[p][c]) return0; p = nex[p][c]; } return exist[p]; } };
structTRIE { int nex[10000000][26], cnt; int exist[10000000]; // 该结点结尾的字符串是否存在
voidinsert(char* s, int l)// 插入字符串 { int p = 0; for (int i = 0; i < l; i++) { int c = s[i] - 'a'; if (!nex[p][c]) nex[p][c] = ++cnt; // 如果没有,就添加结点 p = nex[p][c]; } exist[p] = 1; } intfind(char* s, int l)// 查找字符串 { int p = 0; for (int i = 0; i < l; i++) { int c = s[i] - 'a'; if (!nex[p][c]) return0; p = nex[p][c]; } if (exist[p]) return exist[p]++; } };
TRIE trie;
intmain() { scanf("%d", &n); while (n--) { scanf("%s", x); int l = strlen(x); trie.insert(x, l); } scanf("%d", &n); while (n--) { scanf("%s", x); int l = strlen(x); int ans = trie.find(x, l); if (ans) { if (ans == 1) printf("OK\n"); elseprintf("REPEAT\n"); } elseprintf("WRONG\n"); }
return0;
}
About this Post
This post is written by OwlllOvO, licensed under CC BY-NC 4.0.