/*It's not a difficult question, but it's a matter of the dictionary tree, but space is a problem. Start writing such a struct node{int next[27],sum[27]; bool over;} T[MAXN]; It's not going to work. The ER opened up the MLE asked Wmy very witty said with map works and then the card space to see them using pointers to dynamically allocate memory but I'm not very good at it .*/#include<iostream>#include<cstdio>#include<cstring>#include<map>#defineMAXN 480010using namespacestd;inttopt;Chars[ -];structnode{Map<int,int>next,sum; BOOLOver ;} T[MAXN];voidAdd_tree () {intnow=0, l=strlen (s); for(intI=0; i<l;i++) { intx=s[i]-'a'+1; if(T[now].next[x]) {t[now].sum[x]++; now=T[now].next[x]; } Else{topt++;t[now].next[x]=topt; T[NOW].SUM[X]++;now=topt; } }}intFind_tree () {intans=0, p=0, now=0, l=strlen (s), X,pre; while(p<=l-1) {x=s[p]-'a'+1; if(T[now].next[x]) pre=now,now=t[now].next[x],p++; Else return 0; } returnt[pre].sum[x];}intMain () { while(Gets (s) &&strlen (s)) Add_tree (); while(Gets (s)) Cout<<find_tree () <<Endl; return 0;}
HUD 1251 Puzzle Stats