HDU 1251 Statistical Puzzles (Tire tree)

Source: Internet
Author: User

Statistical puzzles



Problem Descriptionignatius recently encountered a problem, the teacher gave him a lot of words (only lowercase letters, no duplicate words appear), now the teacher asked him to count the number of words prefixed with a string (the word itself is also its own prefix).

The first part of input data is a Word table, one word per line, the length of the word is not more than 10, they represent the word that the teacher handed to Ignatius, and a blank line represents the end of the Word table. The second part is a series of questions, one question per line, and each question is a string.

Note: There is only one set of test data, processing to the end of the file.

Output for each question, give the number of words prefixed with the string.

Sample INPUTBANANABANDBEEABSOLUTEACM BABBANDABC

Sample Output2310
1#include <cstdio>2#include <malloc.h>3#include <cstring>4 using namespacestd;5 6 Const intmaxn= -;7 8 structTire9 {TenTire *NEXT[MAXN]; One     intv; A Tire () -     { -Memset (Next,0,sizeof(next)); thev=0; -     } - }; -  +Tire *root=NewTire; -  + voidCreattire (Char*str) A { at     intlen=strlen (str); -Tire *p=Root; -      for(intI=0; i<len;i++) -     { -         intid=str[i]-'a'; -         if(p->next[id]==NULL) in         { -Tire *q=NewTire; toq->v=1; +p->next[id]=Q; -P=p->Next[id]; the         } *         Else $         {Panax Notoginsengp->next[id]->v++; -P=p->Next[id]; the         } +     } A } the  + intFindtire (Char*str) - { $     inti; $     intlen=strlen (str); -Tire *p=Root; -      for(i=0; i<len;i++) the     { -         intid=str[i]-'a';Wuyi         if(p->next[id]==NULL) the             return 0; -P=p->Next[id]; Wu     } -     returnP->v; About } $  - intMain () - { -     //freopen ("In.txt", "R", stdin); A     Chars[ One]; +      while(Gets (s) &&s[0]!=' /') the     { - Creattire (s); $     } the      while(SCANF ("%s", s)! =EOF) the     { the         intans=Findtire (s); theprintf"%d\n", ans); -     } in     return 0; the}

HDU 1251 Statistical Puzzles (Tire 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.