1 // 2 // trie树模板.cpp 3 // 7.24集训 4 // 5 // Created by skygao on 2019/7/24. 6 // Copyright © 2019 skygao. All rights reserved. 7 // 8 9 #include <stdio.h> 10 #include <cstdlib> 11 #include <string> 12 #include <cstring> 13 #include <iostream> 14 #include <algorithm> 15 #define maxn 10005 16 #define maxm 100005 17 #defineRegister Re 18 is the using namespace STD; . 19 const int SZ = 26 ; // size of the character set (26 lowercase letters) 20 is char ST [MAXN]; // to be inserted into the string 21 is struct the Node 22 is { 23 is int CH [SZ ]; 24 int in Flag; // current node is not the end of a string 25 } MAXM a []; 26 is int the root = 0 , node_num = 0 ; 27 void INSERT ( int X, int I, int L)// L st length of the string to be inserted 28 { 29 IF (I == L) 30 { 31 is A [X] = .flag to true ; 32 return ; 33 is } 34 is int C st = [I] - ' A ' ; 35 IF (! A [X] .ch [C]) 36 A [X] .ch [C] = ++ node_num; 37 [ INSERT (A [X] .ch [C], + I . 1 , L); 38 is } 39 int main () 40 { 41 is 42 is return 0 ; 43 }