题目背景
XS中学化学竞赛组教练是一个酷爱炉石的人。
他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900)。
题目描述
这之后校长任命你为特派探员,每天记录他的点名。校长会提供化学竞赛学生的人数和名单,而你需要告诉校长他有没有点错名。(为什么不直接不让他玩炉石。)
输入输出格式
输入格式:
第一行一个整数 n,表示班上人数。接下来 n 行,每行一个字符串表示其名字(互不相同,且只含小写字母,长度不超过 50)。第 n+2 行一个整数 m,表示教练报的名字。接下来 m 行,每行一个字符串表示教练报的名字(只含小写字母,且长度不超过 50)。
输出格式:
对于每个教练报的名字,输出一行。如果该名字正确且是第一次出现,输出“OK”,如果该名字错误,输出“WRONG”,如果该名字正确但不是第一次出现,输出“REPEAT”。(均不加引号)
输入输出样例
输入样例#1:
5 a b c ad acd 3 a a e输出样例#1:
OK REPEAT WRONG说明
对于 40%的数据,n≤1000,m≤2000;
对于 70%的数据,n≤10000,m≤20000;
对于 100%的数据, n≤10000,m≤100000。
trie乱搞呗。。。
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cstring> 5 #include <cstdlib> 6 #include <list> 7 #include <map> 8 9 using namespace std; 10 11 typedef unsigned long long ull; 12 13 struct Node 14 { 15 int vis; 16 bool isEnd; 17 Node *next[30]; 18 19 } * root, mem[600000]; 20 21 Node *newNode() 22 { 23 static int p = 0; 24 p++; 25 return &mem[p]; 26 } 27 28 int n; 29 30 char str[100]; 31 32 void insert(char *str) 33 { 34 Node *rt = root; 35 for (char *s = str; *s; s++) 36 { 37 if (!rt->next[*s - 'a']) 38 rt->next[*s - 'a'] = newNode(); 39 rt = rt->next[*s - 'a']; 40 } 41 rt->isEnd = true; 42 } 43 44 bool find(char *str) 45 { 46 Node *rt = root; 47 for (char *s = str; *s; s++) 48 { 49 rt = rt->next[*s - 'a']; 50 if (!rt) 51 return false; 52 } 53 return rt->isEnd; 54 } 55 56 bool visited(char *str) 57 { 58 Node *rt = root; 59 for (char *s = str; *s; s++) 60 rt = rt->next[*s - 'a']; 61 return rt->vis++ != 0; 62 } 63 64 int main() 65 { 66 root = newNode(); 67 scanf("%d", &n); 68 while (n--) 69 { 70 scanf("%s", str); 71 insert(str); 72 } 73 scanf("%d", &n); 74 while (n--) 75 { 76 scanf("%s", str); 77 if (find(str)) 78 { 79 if (visited(str)) 80 { 81 puts("REPEAT"); 82 } 83 else 84 { 85 puts("OK"); 86 } 87 } 88 else 89 { 90 puts("WRONG"); 91 } 92 } 93 }