I began to think of the simple, WA once, and then look at Disscuss someone said the input length from small to large, and then I believe. Then start while (1) WA; Then I try to put the array first. Later on;
Discuss inside is not too believed.
Determines whether the prefix is based on the number of occurrences.
#include <stdio.h>#include<string.h>#include<stdlib.h>structtrie{trie*next[2]; intsum;}; Trie*Root;voidCreattrie () {root= (trie*)malloc(sizeof(trie)); for(intI=0;i<2; i++) {root->next[i]=NULL; } Root->sum=0;}voidInsertChar*str) { intI,j,cnt=0; intlen=strlen (str); Trie*p=root,*Q; for(i=0; i<len;i++) { intid=str[i]-'0'; if(p->next[id]==NULL) {Q= (trie*)malloc(sizeof(trie)); for(j=0;j<2; j + +) Q->next[j]=NULL; Q->sum=0; P->next[id]=Q; } P=p->Next[id]; P->sum++; }}intQueryChar*str) { inti,j; intCnt=0; intlen=strlen (str); Trie*p=Root; for(i=0; i<len;i++) { intid=str[i]-'0'; P=p->Next[id]; } if(p->sum>1)//when the string ends, the sum is now more than 2, if it is, then there is a word prefixed with this.Cnt=1; if(CNT)return 1; return 0;}intMain () {inti,j,flag,ff=0, Ret,count; Charstr[ -][ -]; while(Gets (str[0])!=NULL) { if(str[0][0]=='9') Break; Count=1; Creattrie (); Insert (str[0]); while(Gets (Str[count])) {if(str[count][0]=='9') Break; Insert (Str[count]); Count++; } Flag=0; for(i=0; i<count;i++) {flag=query (Str[i]); if(flag) Break; } if(flag) printf ("Set%d is not immediately decodable\n",++ff); Elseprintf"Set%d is immediately decodable\n",++ff); } return 0;}
hdu1305 Simple Dictionary Tree