P2580 started with his wrong name, And P2580 ended with a wrong name.
Background
XS high school chemistry competition team coach is a love for hearth stone.
He will roll the hearth stone and name it so that one day he points to a classmate twice in a row, then it was discovered by the passing principal, followed by a ton of Oula Euler's (for details, see the end of the Competition CON900 ).
Description
After that, the principal appointed you as a special agent and recorded his name every day. The principal will provide the number and list of students in the chemistry competition, and you need to tell the principal if he has a wrong name. (Why not let him play hearth stone .)
Input/Output Format
Input Format:
The first line is an integer n, indicating the number of students in the class. In the next n rows, one string in each row indicates the name of a string (each of which contains only lower-case letters and cannot exceed 50 ). The n + 2 line is an integer m, indicating the name of the coach report. In the next m row, each line contains a string indicating the name of the coach report (only lowercase letters are included and the length cannot exceed 50 ).
Output Format:
For the name reported by each coach, output a line. If the name is correct and appears for the first time, "OK" is output. If the name is incorrect, "WRONG" is output. If the name is correct but not the first time, "REPEAT" is output ". (No quotation marks are added)
Input and Output sample input sample #1:
5 abcadacd3aae
Output sample #1:
OKREPEATWRONG
Description
For 40% of data, n ≤ 1000, m ≤ 2000;
For 70% of data, n ≤ 10000, m ≤ 20000;
For 100% of data, n ≤ 10000, m ≤ 100000.
T1 always sends points.
TRIE's bare question ,,
However.
The array is small ,,
Adjusted for an hour ..
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <queue> 6 # include <algorithm> 7 # define lli long int 8 using namespace std; 9 const int MAXN = 500001; 10 void read (int & n) 11 {12 char c = '+'; lli x = 0, flag = 1; 13 while (c <'0' | c> '9') {c = getchar (); if (c = '-') flag =-1 ;} 14 while (c> = '0' & c <= '9') {x = x * 10 + c-48; c = getchar ();} 15 n = x * flag; 16} 17 int n, m; 18 char s [MAXN]; 19 int h Ave [MAXN]; 20 struct TRIE21 {22 int ch [MAXN] [28]; 23 int val [MAXN]; // whether it is the end of a word and whether it is repeated. 24 int sz; // Number of children 25 TRIE () 26 {27 memset (ch [0], 0, sizeof (ch [0]); 28 memset (val, 0, sizeof (val); 29 memset (have, 0, sizeof (have); 30 sz = 1; // initialize 31} 32 int idx (char c) 33 {34 return c-'A'; // 35} 36 void Insert (char * s) 37 {38 int l = strlen (s); int x = 0; 39 for (int I = 0; I <l; I ++) 40 {41 int c = idx (s [I]); 42 if (! Ch [x] [c]) 43 {44 memset (ch [sz], 0, sizeof (ch [sz]); 45 ch [x] [c] = sz ++; 46} 47 x = ch [x] [c]; 48 val [x] = 1; 49} 50 have [x] = 1; 51} 52 void find (char * s) 53 {54 int l = strlen (s); int x = 0; 55 bool flag = 0; 56 for (int I = 0; I <l; I ++) 57 {58 int c = idx (s [I]); 59 if (! Ch [x] [c]) 60 {61 printf ("WRONG \ n"); 62 return; 63} 64 x = ch [x] [c]; 65} 66 if (have [x] = 0) 67 {68 printf ("WRONG \ n"); 69 return; 70} 71 else if (have [x] = 1) 72 {73 printf ("OK \ n"); 74 have [x] ++; 75} 76 else 77 printf ("REPEAT \ n"); 78} 79} trie; 80 int main () 81 {82 read (n ); 83 for (int I = 1; I <= n; I ++) 84 {85 scanf ("% s", s); 86 trie. insert (s); 87} 88 read (m); 89 for (int I = 1; I <= m; I ++) 90 {91 scanf ("% s ", s); 92 trie. find (s); 93} 94 return 0; 95}