博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
What Are You Talking About HDU - 1075(字典树)
阅读量:4556 次
发布时间:2019-06-08

本文共 5078 字,大约阅读时间需要 16 分钟。

What Are You Talking About HDU - 1075

题目链接:

题目:

Ignatius 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 him?
InputThe 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 "START", this string should be ignored, then some lines follow, each line contains 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 "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", 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 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 string "END" 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.
OutputIn this problem, you have to output the translation of the history book.
Sample Input
STARTfrom fiwohello difhmars riwosfearth fnnvklike fiiwjENDSTARTdifh, i'm fiwo riwosf.i fiiwj fnnvk!END
Sample Output
hello, i'm from mars.i like earth!
Hint
Huge input, scanf is recommended.
Ignatius 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 him?
InputThe 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 "START", this string should be ignored, then some lines follow, each line contains 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 "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", 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 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 string "END" 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.
OutputIn this problem, you have to output the translation of the history book.
Sample Input
STARTfrom fiwohello difhmars riwosfearth fnnvklike fiiwjENDSTARTdifh, i'm fiwo riwosf.i fiiwj fnnvk!END
Sample Output
hello, i'm from mars.i like earth!
Hint
Huge input, scanf is recommended.         题意:火星文翻译,标点符号不变   思路:这题也可以不用字典树来求,可以用map来求,练习一下字典树,所以就来写一下字典树的写法:
// // Created by HJYL on 2019/8/19.//#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;const int maxn=1e6+10;struct trie{ trie* next[26]; int sum=0; char str[20];}root;void init(trie *a){ for(int i=0;i<26;i++) a->next[i]=NULL; a->sum=0;}trie *root1=new trie;void insert(char* s,char* s2){ int len=strlen(s); trie *p=root1; for(int i=0;s[i];i++) { if(p->next[s[i]-'a']==NULL) { p->next[s[i]-'a']=new trie; trie *n=new trie; init(n); p->next[s[i]-'a']=n; p=p->next[s[i]-'a']; } else p=p->next[s[i]-'a']; } p->sum=1; strcpy(p->str,s2);}char* find(char *s){ int len=strlen(s); trie *p=root1; for(int i=0;i
next[s[i]-'a']==NULL) return s; p=p->next[s[i]-'a']; } if(p->sum) return p->str; return s;}int main(){ //freopen("C:\\Users\\asus567767\\CLionProjects\\untitled\\text","r",stdin); char str[maxn],str1[maxn]; char ch; init(root1); scanf("%s",str); while(scanf("%s",str1)&&strcmp(str1,"END")) { scanf("%s",str); insert(str,str1); } scanf("%s",str); getchar(); int len2; while(gets(str)&&strcmp(str,"END")) { int len=strlen(str); len2=0; for(int i=0;i

 

转载于:https://www.cnblogs.com/Vampire6/p/11380470.html

你可能感兴趣的文章
字符串中的数字(字符串、循环)
查看>>
15.select into
查看>>
缓存-->Java中缓存的原理
查看>>
Activity 和Service绑定
查看>>
URAL 1348 求垂足
查看>>
flume-agent实例
查看>>
【VS开发】CListCtrl控件使用方法总结
查看>>
【神经网络与深度学习】公开的海量数据集
查看>>
03 docker容器镜像基础
查看>>
bzoj 3620 暴力KMP
查看>>
Excel word “由于本机的限制_该操作已被取消_请与管理员联系”的已生效解决办法 (转 )...
查看>>
解压cpio.gz、zip类型文件
查看>>
静态属性和静态方法
查看>>
高效的MySQL分页
查看>>
MooTools 1.2 Beginner's Guide
查看>>
计算储存、交互和语言
查看>>
bzoj2067: [Poi2004]SZN
查看>>
所谓独立环境
查看>>
当代GSM手机的硬件系统分析[zz]
查看>>
对我影响最深的三个老师
查看>>