hdu1305 Simple Dictionary Tree

Source: Internet
Author: User

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

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.