HDU1075 dictionary tree + string map

Source: Internet
Author: User

Topic Link: http://acm.hdu.edu.cn/showproblem.php?pid=1075, string mapping of the dictionary tree.

  

Test instructions is to give you every Martian word corresponding to the English, and then let you put a Martian article translated into English.

Solution:

Add a string to each end flag in the trie tree, so that you can construct a map for each Martian word. After constructing the map, you can work with the translation section, you can read the line with get, and then handle the line, noting the punctuation. Finally, note that the array is larger.

#include <iostream>#include<cstdio>#include<vector>#include<queue>#include<stack>#include<cmath>#include<string>#include<string.h>#include<algorithm>using namespacestd;#defineLL __int64Const intMAXN =500000+5;Const intSigma_size = -;structTrie {intCh[maxn][sigma_size]; Charstr[maxn][ the]; BOOLISEND[MAXN]; intsize; voidinit () {size=1; memset (ch[0] ,0,sizeof(ch[0])); memset (Isend,0,sizeof(Isend)); }    intIndexCharc) {returnC'a'; }    voidInsertChar*s,Char*S0) {        intI, RT;  for(i = RT =0; S[i]! =' /'; i++) {            intc =index (s[i]); if(!Ch[rt][c]) {memset (ch[size],0,sizeof(Ch[size])); CH[RT][C]= size++; } RT=Ch[rt][c];        } strcpy (Str[rt], s0); ISEND[RT]=1; }    Char*find (Char*s) {intI, RT;  for(i = RT =0; S[i]! =' /'; i++) {            intc =index (s[i]); if(!Ch[rt][c])return "0"; RT=Ch[rt][c]; }        return(Isend[rt])? STR[RT]:"0"; }} trie;CharS1[MAXN], S2[MAXN];intMain () {trie.init ();  while(~SCANF ("%s", S1)) {        if(!STRCMP (S1,"START"))Continue; if(!STRCMP (S1,"END")) Break; scanf ("%s", S2);    Trie.insert (S2, S1);    } getchar ();  while(Gets (S1)) {if(!STRCMP (S1,"START"))Continue; if(!STRCMP (S1,"END")) Break; inti =0;  while(S1[i]! =' /') {            if(S1[i] >='a'&& S1[i] <='Z') {                intj =0;  while(S1[i]! =' /'&& S1[i] >='a'&& S1[i] <='Z') {s2[j+ +] = s1[i++]; } S2[j]=' /'; Char*tmp =trie.find (S2); if(tmp[0] =='0') printf ("%s", S2); Elseprintf"%s", TMP); } Else{Putchar (s1[i++]); }} puts (""); }    return 0;}

HDU1075 dictionary tree + string map

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.