"hdu1247" Hat ' s Words

Source: Internet
Author: User

Descriptiona Hat's word is a word in the dictionary so is the concatenation of exactly and the other words in the dictionary .
You're to find all the hat's words in a dictionary. Inputstandard input consists of a number of lowercase words, one per line, in alphabetical order. There'll be is no more than 50,000 words.
Only one case. Outputyour output should contain all the hat's words, one per line, in alphabetical order. Sample Inputaahathathatwordhzieewordsample Outputahathatwordauthor a hat

The question means: give a bunch of strings, and judge which string can be connected to the two strings in this pile.

Trie tree. Read the string first, then enumerate each of the possible judgments.

S.substr (I,J) string s intercept J-bit starting from I

Next is going to open 27. (0 inside is empty)

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;structnode{intnext[ -]; intW;} t[50010];stringss[50010];strings;inttopt,cnt;voidAdd_trie () {intL=s.length (), now =0;  for(intI=0; i<l;i++)    {        intx = s[i]-'a'+1; if(T[now].next[x]) now=T[now].next[x]; Else{t[now].next[x]= ++topt; now=topt; }} T[NOW].W=1;}intfind () {intL=s.length (), now =0, p =0;  while(p<l) {if(!t[now].next[s[p]-'a'+1])return 0; Else{ Now= t[now].next[s[p]-'a'+1]; P++; }    }    if(T[NOW].W)return 1; Else return 0;}intMain () { while(cin>>ss[++CNT]) {s=ss[cnt];    Add_trie (); }     for(intI=1; i<cnt;i++)    {        strings3=Ss[i]; intL=s3.length ();  for(intj=1; j<l;j++) {s=S3.SUBSTR (0, J); if(Find ()) {s=s3.substr (j,l); if(Find ()) {cout<<s3<<Endl;  Break; }            }        }    }    }

"hdu1247" Hat ' s Words

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.