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