Luo Gu P2580 [he] began the roll call the wrong solution to a problem

XS school chemistry competition coach is a group of people fond of furnace slag. 

He would rub furnace slag while the side that day he named successive points to a classmate twice, and then just to be passing principal meal is then found欧拉欧拉欧pull (For details, see the game has ended CON900).
Topic background
After that the principal mission appointed you as a detective, to record his attendance every day. Principals will be provided and the number of students chemistry competition list, and you need to tell the president he has no point the wrong name. (Why not just let him play hearth.)
Title Description
The first line an integer n, the number of people in the class. Next n lines, each line a string representation of the name (different from each other, and contain only lowercase letters, no longer than 50 ). Of + n- 2 line of an integer m, represents the name of the coach reported. Subsequently m rows, each row represents the name of a string of packets coach (containing only lowercase letters, and the length does not exceed 50 ).
Input Format
For the name of each coach reported, the output line. If the name is correct and is the first time, output "OK", if the name of the error, the output "WRONG", if the name is correct but not the first time, the output "REPEAT". (Not in quotes)
Output Format
5   
to 
b 
c 
d 
acd 
3 
to 
be 
a
SAMPLE INPUT
OK
REPEAT
WRONG
Sample Output
For 40 % of the data, N ≤ 1000 , m ≤ 2000 ; 

for 70 % of the data, N ≤ 10000 , m ≤ 20000 ; 

for 100 % of the data, N ≤ 10000 , m ≤ 100000. .
data range

A trie tree water problem. . . . .

Beginning to open a small array, and thought it was a trie write explode

Then try holding the idea changed a bit array size

Then the AC. . .

#include <the iostream> 
#include <cstdio> 
#include <CString> 
#include <Map> the using namespace STD; 
Map < String , int > In Flag;
 int Trie [ 1000100 ] [ 51 is ];
 String S; // character input using string int TOT = 0 ; // current number which void INSERT () 
{ int len = s.length ();
     int the root = 0 ;
     for ( int I =

 




    0 ; I <len; I ++) // in turn placed 
    {
         int ID = S [I] - ' A ' ;
         IF (Trie [the root] [ID])! // is not present in this node 
        { 
            Trie [the root] [ID] ++ TOT =; // placed, numeral 
        } 
        the root = Trie [the root] [ID]; // then continue to look down 
    } 
} 

BOOL find () 
{ 
    int len = s.length ();
     int the root = 0 ;
     for ( int I = 0 ; S [I]; I ++ ) 
    {
        int X = S [I] - ' A ' ;
         IF (Trie [the root] [X]) 
        { 
            the root = Trie [the root] [X]; // have this node, i.e. the matched 
        }
         the else 
        return  to false ; / / not coupled directly ends 
    }
     return  to true ; // the matching 
} 

int main () 
{ 
    int n-; 
    CIN >> n-;
     for ( int I = . 1 ; I <= n-; I ++ ) 
    { 
        CIN >> S;
        INSERT (); 
    } 
    int m; 
    CIN >> m;
     for ( int I = . 1 ; I <= m; I ++ ) 
    { 
        CIN >> S;
         IF (Find () && In Flag [S] == 0 ) // on the mating and the first time 
        { 
            In Flag [S] = . 1 ; 
            COUT << " the OK " << endl; 
        } 
        the else  IF (! In Flag [S] = 0 & Find ()) // the match but not the first time 
        { 
            cout<<"REPEAT"<<endl;
        }
        else//没有匹配上 
        {
            cout<<"WRONG"<<endl;
        }
    }
    return 0;
}
AC Code

 

Guess you like

Origin www.cnblogs.com/Soroak/p/11323099.html