HDU - 1075 - What Are You Talking About
2017-08-07 18:55
344 查看
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
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, 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,也可以用字典树
需要转换的数据可能前面有空格什么的,要注意一下,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; }
相关文章推荐
- hdu 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu 1075 What Are You Talking About(给你字典,让你翻译句子,字典中查不到的单词不用翻译)
- What Are You Talking About hdu1075
- hdu 1075 What Are You Talking About ( trie + 模拟 )
- HDU1075 What Are You Talking About 解题报告--字典树
- HDU 1075 What Are You Talking About(map映照容器)(搜索)
- HDU 1075 What Are You Talking About
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
- HDU-1075-What Are You Talking About(字典树&map)
- HDU 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About
- HDU-1075-What Are You Talking About
- 【HDU 1075】What Are You Talking About(字典树)
- HDU_1075_What Are You Talking About(字典树)
- hdu 1075 What Are You Talking About
- HDU 1075-What Are You Talking About(字符串)
- HDU 1075 What Are You Talking About (字典树)
- hdu 1075 What Are You Talking About【字典树】
- hdu 1075 What Are You Talking About(map)