HDU 1247 hat's words

Source: Internet
Author: User

I did the dictionary tree a month ago. I still remember that he was the first dictionary tree in my AC. Hey.

ACCode:

View code

# Include <algorithm> # Include <Iostream> # Include <Cstdlib> # Include <Cstdio> # Include <Cstring> # Include < String > # Include < Set > Using  Namespace  STD;  Const   Int Maxn = 26  ;  Const   Int Maxlen = 100  ;  Char SS1 [ 50005  ] [Maxlen], ss2 [maxlen], ss3 [maxlen];  Struct  Node {  Bool Flg; Node * Next [maxn]; node () {flg = False  ;  For ( Int I = 0 ; I <maxn; I ++ ) Next [I] = NULL ;} ~ Node (){  For ( Int I = 0 ; I <maxn; I ++)  If (Next [I]! = NULL) next [I] = Null ;}};  Class  Trie {  Public  : Node * Root; trie () {Root = NULL ;}  Void Insert ( String  Str ){  If (! Root) Root =New  Node (); Node * Location = Root;  For ( Int I = 0 ; I <Str. Length (); I ++ ){  Int Num = STR [I]- '  A  '  ;  If (Location-> next [num] = Null) Location -> Next [num] = New  Node (); Location = Location-> Next [num];} location -> Flg = True  ;}  Bool Search ( String  Str) {Node * Location = Root;  For ( Int I = 0 ; I <Str. Length (); I ++){  Int Num = STR [I]- '  A  '  ;  If (Location-> next [num] = Null)  Return   False  ; Location = Location-> Next [num];}  Return Location-> Flg ;}} T; Int  Main (){  String  Str1, str2;  Int Line = 0  ; Memset (SS1,  '   ' , Sizeof  (SS1 ));  While  (CIN. Getline (SS1 [Line], maxlen) {str1 = SS1 [Line ++ ]; T. insert (str1 );}  For ( Int I = 0 ; I <line; I ++ ){  For ( Int J = 1 ; J <strlen (SS1 [I]); j ++ ) {Str1 = Str2 = ""  ; Memset (ss2,  '   ' , Sizeof  (Ss2); memset (ss3, '   ' , Sizeof  (Ss3); strncpy (ss2, SS1 [I], J); ss2 [J] = '  \ 0  '  ; Strncpy (ss3, SS1 [I] + J, strlen (SS1 [I])- J); ss3 [strlen (SS1 [I]) -J] = '  \ 0  '  ;  // Cout <ss2 <''<ss3 <Endl; Str1 = ss2, str2 = Ss3;  If (T. Search (str1 )&& T. Search (str2) {cout <SS1 [I] < Endl;  //  System ("pause ");                  Break  ;}}}  Return   0  ;} 

Thank you for your criticism. Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.