{"id":351,"date":"2013-03-13T10:56:00","date_gmt":"2013-03-13T02:56:00","guid":{"rendered":"http:\/\/nike0good.jp1.rpvhost.net\/255"},"modified":"2013-03-13T10:56:00","modified_gmt":"2013-03-13T02:56:00","slug":"hdu_1075_what_are_you_talking_about-trie_insert_and_search","status":"publish","type":"post","link":"https:\/\/nike0good.com\/?p=351","title":{"rendered":"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e)"},"content":{"rendered":"<h1 style=\"color:rgb(26,92,200); text-align:center; font-family:'Times New Roman'\">\nWhat Are You Talking About<\/h1>\n<p><span style=\"font-family:'Times New Roman'; font-size:14px\"><strong><span style=\"font-family:Arial; font-size:12px; color:green\">Time Limit: 10000\/5000 MS (Java\/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: 102400\/204800 K (Java\/Others)<br \/>\nTotal Submission(s): 8571&nbsp;&nbsp;&nbsp;&nbsp;Accepted Submission(s): 2696<br \/>\n<\/span><\/strong><\/span><br style=\"font-family:'Times New Roman'; font-size:14px\" \/><br \/>\n<br style=\"font-family:'Times New Roman'; font-size:14px\" \/><\/p>\n<div class=\"panel_title\" align=\"left\" style=\"height:38px; background-color:transparent; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold\">\nProblem Description<\/div>\n<div class=\"panel_content\" style=\"height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'\">\nIgnatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help<br \/>\n him?\n<\/div>\n<div class=\"panel_bottom\" style=\"height:auto; margin:0px; font-family:'Times New Roman'; font-size:14px\">\n&nbsp;<\/div>\n<p><br style=\"font-family:'Times New Roman'; font-size:14px\" \/><\/p>\n<div class=\"panel_title\" align=\"left\" style=\"height:38px; background-color:transparent; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold\">\nInput<\/div>\n<div class=\"panel_content\" style=\"height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'\">\nThe problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string &quot;START&quot;, this string should be ignored, then some lines follow, each line contains<br \/>\n two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string &quot;END&quot; indicates the end of the directory part, and this string should be ignored. The book part starts with a single<br \/>\n line contains a string &quot;START&quot;, this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new<br \/>\n word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab('t'), enter('n') and all the punctuation should not be translated. A line with a single<br \/>\n string &quot;END&quot; indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.\n<\/div>\n<div class=\"panel_bottom\" style=\"height:auto; margin:0px; font-family:'Times New Roman'; font-size:14px\">\n&nbsp;<\/div>\n<p><br style=\"font-family:'Times New Roman'; font-size:14px\" \/><\/p>\n<div class=\"panel_title\" align=\"left\" style=\"height:38px; background-color:transparent; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold\">\nOutput<\/div>\n<div class=\"panel_content\" style=\"height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'\">\nIn this problem, you have to output the translation of the history book.\n<\/div>\n<div class=\"panel_bottom\" style=\"height:auto; margin:0px; font-family:'Times New Roman'; font-size:14px\">\n&nbsp;<\/div>\n<p><br style=\"font-family:'Times New Roman'; font-size:14px\" \/><\/p>\n<div class=\"panel_title\" align=\"left\" style=\"height:38px; background-color:transparent; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold\">\nSample Input<\/div>\n<div class=\"panel_content\" style=\"height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'\">\n<pre style=\"margin-top:0px; margin-bottom:0px\"><div style=\"font-family:'Courier New',Courier,monospace\">START\nfrom fiwo\nhello difh\nmars riwosf\nearth fnnvk\nlike fiiwj\nEND\nSTART\ndifh, i'm fiwo riwosf.\ni fiiwj fnnvk!\nEND<\/div><\/pre>\n<\/div>\n<div class=\"panel_bottom\" style=\"height:auto; margin:0px; font-family:'Times New Roman'; font-size:14px\">\n&nbsp;<\/div>\n<p><br style=\"font-family:'Times New Roman'; font-size:14px\" \/><\/p>\n<div class=\"panel_title\" align=\"left\" style=\"height:38px; background-color:transparent; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold\">\nSample Output<\/div>\n<div class=\"panel_content\" style=\"height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'\">\n<pre style=\"margin-top:0px; margin-bottom:0px\"><div style=\"font-family:'Courier New',Courier,monospace\">hello, i'm from mars.\ni like earth!\n\n<div style=\"font-family:'Times New Roman'; background-color:rgb(244,251,255); border:1px dashed rgb(183,203,255); padding:6px\"><div style=\"font-family:Arial; font-weight:bold; color:rgb(124,169,237); border-bottom-color:rgb(183,203,255); border-bottom-width:1px; border-bottom-style:dashed\"><em>Hint<\/em><\/div>\nHuge input, scanf is recommended.\n<\/div><span style=\"font-size:1px\"> <\/span><\/div><\/pre>\n<\/div>\n<div class=\"panel_bottom\" style=\"height:auto; margin:0px; font-family:'Times New Roman'; font-size:14px\">\n&nbsp;<\/div>\n<p><br style=\"font-family:'Times New Roman'; font-size:14px\" \/><\/p>\n<div class=\"panel_title\" align=\"left\" style=\"height:38px; background-color:transparent; padding:0px 14px; color:rgb(124,169,237); font-size:18px; font-family:Arial; font-weight:bold\">\nAuthor<\/div>\n<div class=\"panel_content\" style=\"height:auto; margin:0px; padding:0px 20px; font-size:14px; font-family:'Times New Roman'\">\nIgnatius.L<\/div>\n<div class=\"panel_bottom\" style=\"height:auto; margin:0px; font-family:'Times New Roman'; font-size:14px\">\n&nbsp;<\/div>\n<p><\/p>\n<p><span style=\"font-size:14px\">Trie\u7684\u63d2\u5165\u548c\u67e5\u627e<\/span><\/p>\n<p><span style=\"font-size:14px\">\u8bdd\u8bf4\u4e5f\u4e0d\u96be\u554a\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size:14px\"><\/span><\/p>\n<pre name=\"code\" class=\"cpp\">#include&lt;cstdio&gt;\n#include&lt;cstring&gt;\n#include&lt;algorithm&gt;\n#include&lt;functional&gt;\n#include&lt;cstdlib&gt;\n#include&lt;iostream&gt;\n#include&lt;cctype&gt;\nusing namespace std;\n#define MAXWordlen (10+10)\n#define MAXLen (3000+10)\nchar s[MAXLen];\nchar word[MAXWordlen],word1[MAXWordlen];\nstruct node\n{\n\tnode *next[26+1];\n\tchar t[MAXWordlen];\n\tnode()\n\t{\n\t\tt[0]=0;\n\t\tfor (int i=0;i&lt;=26;i++) next[i]=NULL;\n\t}\n}root;\nvoid insert(char *str,char str1[])\n{\n\tint len=strlen(str);\n\tnode *p=&amp;root;\n\tfor (int i=0;i&lt;len;i++)\n\t{\n\t\tif (p-&gt;next[str[i]-'a']==NULL) p-&gt;next[str[i]-'a']=new node();\n\t\tp=p-&gt;next[str[i]-'a'];\n\t}\n\tstrcpy(p-&gt;t,str1);\n}\nnode* find(int l,int r)\n{\n\tnode *p=&amp;root;\n\tfor (int i=l;i&lt;=r;i++)\n\t{\n\t\tif (p-&gt;next[s[i]-'a']==NULL) return 0;\n\t\tp=p-&gt;next[s[i]-'a'];\n\t}\n\tif (strcmp(p-&gt;t,&quot;&quot;)) return p;\n\treturn 0;\n}\nint main()\n{\n\tscanf(&quot;START&quot;);\n\twhile (scanf(&quot;%s&quot;,word)&amp;&amp;strcmp(word,&quot;END&quot;))\n\t{\n\t\tscanf(&quot;%s&quot;,word1);\n\t\tinsert(word1,word);\n\t}\n\tgets(word);\n\tscanf(&quot;START&quot;);\n\tgets(word);\n\twhile (gets(s))\n\t{\n\t\tif (!strcmp(s,&quot;END&quot;)) break;\n\t\tint len=strlen(s);\n\t\ts[len+1]=0;\n\t\tfor (int i=0;i&lt;len;i++)\n\t\t{\n\t\t\tif (islower(s[i]))\n\t\t\t{\n\t\t\t\tint j=i;\n\t\t\t\twhile (islower(s[j+1])) j++;\n\t\t\t\tnode *p=find(i,j);\n\t\t\t\tif (p) printf(&quot;%s&quot;,p-&gt;t);\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tfor (int k=i;k&lt;=j;k++) printf(&quot;%c&quot;,s[k]);\n\t\t\t\t}\n\t\t\t\ti=j;\n\t\t\t}\n\t\t\telse printf(&quot;%c&quot;,s[i]);\n\t\t}\n\t\tprintf(&quot;n&quot;);\n\t}\n\treturn 0;\n}<\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What Are You Talking About Time Limit: 10000\/5000 MS (J [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[3],"tags":[49],"class_list":["post-351","post","type-post","status-publish","format-standard","hentry","category-defaultcategory","tag-tries"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e) - nike0good<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nike0good.com\/?p=351\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e) - nike0good\" \/>\n<meta property=\"og:description\" content=\"What Are You Talking About Time Limit: 10000\/5000 MS (J [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nike0good.com\/?p=351\" \/>\n<meta property=\"og:site_name\" content=\"nike0good\" \/>\n<meta property=\"article:published_time\" content=\"2013-03-13T02:56:00+00:00\" \/>\n<meta name=\"author\" content=\"nike0good\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"nike0good\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=351#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=351\"},\"author\":{\"name\":\"nike0good\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"headline\":\"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e)\",\"datePublished\":\"2013-03-13T02:56:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=351\"},\"wordCount\":349,\"commentCount\":0,\"keywords\":[\"Tries\"],\"articleSection\":[\"DefaultCategory\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=351#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=351\",\"url\":\"https:\\\/\\\/nike0good.com\\\/?p=351\",\"name\":\"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e) - nike0good\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\"},\"datePublished\":\"2013-03-13T02:56:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=351#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=351\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=351#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nike0good.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\",\"url\":\"https:\\\/\\\/nike0good.com\\\/\",\"name\":\"nike0good\",\"description\":\"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nike0good.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\",\"name\":\"nike0good\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"caption\":\"nike0good\"},\"sameAs\":[\"https:\\\/\\\/nike0good.com\"],\"url\":\"https:\\\/\\\/nike0good.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e) - nike0good","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nike0good.com\/?p=351","og_locale":"zh_CN","og_type":"article","og_title":"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e) - nike0good","og_description":"What Are You Talking About Time Limit: 10000\/5000 MS (J [&hellip;]","og_url":"https:\/\/nike0good.com\/?p=351","og_site_name":"nike0good","article_published_time":"2013-03-13T02:56:00+00:00","author":"nike0good","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"nike0good","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nike0good.com\/?p=351#article","isPartOf":{"@id":"https:\/\/nike0good.com\/?p=351"},"author":{"name":"nike0good","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"headline":"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e)","datePublished":"2013-03-13T02:56:00+00:00","mainEntityOfPage":{"@id":"https:\/\/nike0good.com\/?p=351"},"wordCount":349,"commentCount":0,"keywords":["Tries"],"articleSection":["DefaultCategory"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nike0good.com\/?p=351#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nike0good.com\/?p=351","url":"https:\/\/nike0good.com\/?p=351","name":"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e) - nike0good","isPartOf":{"@id":"https:\/\/nike0good.com\/#website"},"datePublished":"2013-03-13T02:56:00+00:00","author":{"@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"breadcrumb":{"@id":"https:\/\/nike0good.com\/?p=351#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nike0good.com\/?p=351"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nike0good.com\/?p=351#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nike0good.com\/"},{"@type":"ListItem","position":2,"name":"HDU 1075(What Are You Talking About-Trie\u7684\u63d2\u5165\u548c\u67e5\u627e)"}]},{"@type":"WebSite","@id":"https:\/\/nike0good.com\/#website","url":"https:\/\/nike0good.com\/","name":"nike0good","description":"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nike0good.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad","name":"nike0good","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","caption":"nike0good"},"sameAs":["https:\/\/nike0good.com"],"url":"https:\/\/nike0good.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=351"}],"version-history":[{"count":0,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/351\/revisions"}],"wp:attachment":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}