This question was previously recorded in our weekly competition, and then we used map.
Because I want to talk about the dictionary tree to my freshman in the past two days, I have to practice a few pieces of code to prevent the freshman from being dizzy ......
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <map> # include <queue> # include <set> # include <cmath> # include <bitset> # define MEM (, b) memset (a, B, sizeof (A) # define lson I <1, L, mid # define rson I <1 | 1, Mid + 1, R # define INF 510010 # define maxn 400010 using namespace STD; typedef long ll; typedef unsigned long ull; int ch [maxn] [27]; // node number int SZ; // number of nodes in the dictionary tree int Val [maxn]; // The number of nodes Value. If it is 1, a new string char STR [maxn] [11] is added. Void Init () // initialization {SZ = 1; memset (CH, 0, sizeof (CH); memset (Val, 0, sizeof (VAL);} void insert (char * s, char * ss) {int u = 0, I, C, L = strlen (SS); for (I = 0; I <L; I ++) {c = ss [I]-'A'; If (! Ch [u] [c]) CH [u] [c] = SZ ++; u = CH [u] [c];} Val [u] = 1; strcpy (STR [u], S);} void query (char * s) {int u = 0, I, C, L = strlen (s), flag = 1; for (I = 0; I <L; I ++) {c = s [I]-'A'; If (! Ch [u] [c]) {flag = 0; break;} u = CH [u] [c];} If (Val [u] & flag) printf ("% s \ n", STR [u]); else puts ("eh");} int main () {char s [22], S1 [12], s2 [12]; Init (); While (gets (s), s [0]! = '\ 0') {int I, Len = strlen (s), j = 0, K = 0, flag = 1; for (I = 0; I <Len; I ++) {If (s [I]! = ''& Flag) S1 [J ++] = s [I]; else if (s [I]! = ''&&! Flag) S2 [k ++] = s [I]; else flag = 0;} S1 [J] = '\ 0'; S2 [k] =' \ 0 '; insert (S1, S2);} while (gets (s) query (s); Return 0 ;}