HDU
来源:互联网 发布:网络整合营销 编辑:程序博客网 时间:2024/06/05 12:00
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 24125 Accepted Submission(s): 8075
Problem Description
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?
Input
The 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.
Output
In 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!HintHuge input, scanf is recommended.
可以用map,也可以用字典树
需要转换的数据可能前面有空格什么的,要注意一下,PE了好几次。
#include<iostream>#include<string.h>#include<stdio.h>#include<string>#include<vector>using namespace std;string s1,s2,s;int num[15];struct node{ vector<node*>next; string s; int num; node() { num = 0; s = ""; next.clear(); }}*tree,*add;string find_and_insert(node *now,int x,int len,int ope){ if(x==len) { if(ope) now->s = s1;//记录该串所对应的单词 return now->s; } for(int i=0;i<now->next.size();i++) { if(now->next[i]->num!=num[x]) continue; return find_and_insert(now->next[i],x+1,len,ope); } if(ope) { add = new node; add->num = num[x]; now->next.push_back(add); return find_and_insert(add,x+1,len,ope); } else return "";}int main(){ tree = new node; add = new node; while(cin>>s1) { if(s1=="START") continue; if(s1=="END") break; cin>>s2; for(int i=0;i<s2.size();i++) num[i] = s2[i] - 'a'; find_and_insert(tree,0,s2.size(),1);//将该单词插入字典树 } cin>>s1;getchar();//“START” s1=s2=""; char str[3030]; memset(str,0,sizeof str); while(gets(str))//可能在每串字符前面也有空格,所以只能用gets()或getchar() { for(int i=0;i<strlen(str);i++) s1+=str[i]; memset(str,0,sizeof str); s=""; if(s1=="END") break; s1+='\n'; int k = 0; for(int i=0;i<s1.size();i++) { if(s1[i]>='a'&&s1[i]<='z') { num[k++] = s1[i] - 'a'; s2 += s1[i]; } else { string ss = find_and_insert(tree,0,k,0); if(ss==""&&s2.size()!=0)//表示这串字母没有对应的单词 s += s2; else s += ss; k=0; s += s1[i]; s2=""; } } s1=""; cout<<s; } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 安装mysql提示 please install the .Net framework
- StringTokenizer
- 第1章:阿里云机器学习实践之路 / 第1节:机器学习背景知识以及业务架构体系
- Ubuntu如何修改系統文件
- MongoDB Java使用指南
- HDU
- 应用缓存(Application Cache)
- jdk环境变量配置&&记事本写程序在cmd执行
- Kotlin——抽象类和接口
- 步进电机的线速度控制
- 共享内存
- 空对象调用属性或方法,equals();;StringBuffer简单用法,字符串的追加,插入和替换。
- 《leetCode》:Longest Common Prefix
- LWLR 局部加权线性回归---Python实现