HDU 1075 What Are You Talking About
2015-07-14 14:40
441 查看
[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
In this problem, you have to output the translation of the history book.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
In this problem, you have to output the translation of the history book.
[align=left]Sample Input[/align]
START from fiwo hello difh mars riwosf earth fnnvk like fiiwj END START difh, i'm fiwo riwosf. i fiiwj fnnvk! END
[align=left]Sample Output[/align]
hello, i'm from mars. i like earth!#include <stdio.h> #include <string.h> char a[1000005][2][15],ans[3005],ch[200]; int main() { int i,j,k,l,temp,m,v; i=0; while(scanf("%s",a[i][0])) { if(!strcmp(a[i][0],"START")) break; } while(~scanf("%s",a[i][0])&&strcmp(a[i][0],"END")!=0) { scanf("%s",a[i++][1]); } m=i; getchar(); while(gets(ans)) { if(!strcmp(ans,"START")) break; } while(gets(ans)) { if(!strcmp(ans,"END")) break; l=strlen(ans); for(i=0;i<l;i++) { if(ans[i]>='a'&&ans[i]<='z') { j=0;temp=1; while(ans[i]>='a'&&ans[i]<='z') { ch[j++]=ans[i++]; } ch[j]='\0'; for(k=0;k<m;k++) if(strcmp(ch,a[k][1])==0) { v=strlen(a[k][0]); for(j=0;j<v;j++) printf("%c",a[k][0][j]); temp=0; } if(temp) { k=strlen(ch); for(j=0;j<k;j++) { printf("%c",ch[j]); } } i--; } else printf("%c",ans[i]); } printf("\n"); } return 0; } #include <iostream> #include <algorithm> #include <map> #include <cstdio> #include <string> #include <string.h> using namespace std; int main() { string a,b; map<string,string> mp; cin>>a; while(cin>>a&&a!="END") { cin>>b; mp[b]=a; } cin>>a; getchar(); char ch[3005]; while(1) { gets(ch); int i,len; if(strcmp(ch,"END")==0) break; len=strlen(ch); b=""; for(i=0;i<len;++i) { if(ch[i]<'a'||ch[i]>'z') { if(mp[b]!="") cout<<mp[b]; else cout<<b; b=""; cout<<ch[i]; } else b+=ch[i]; } cout<<endl; } return 0; }
相关文章推荐
- nc eclipse stadio编译错误怎么办
- 11.字符介绍
- [LeetCode] Binary Tree Level Order Traversal II
- Android命令行工具logcat详细用法!
- 设计模式之Interpreter模式(笔记)
- 有关H.264中NAL的一些疑难点的解释
- 保留小数
- 嵌入式Linux驱动开发案例流程--LED驱动
- ios多线程
- Centos7安装mysql5(linux第二篇记录)
- BOM相关函数
- iOS开发中git分支创建和管理
- Quick-Cocos2d-x 3.3绑定自定义类至Lua(四)使用绑定C++至Lua的自定义类
- Http协议详解
- BigDecimal.setScale 处理java小数点
- 概率dp
- HDU 1240 Asteroids!
- spring接口用户超时验证
- 决策
- Quick-Cocos2d-x 3.3绑定自定义类至Lua(三)动手绑定自定义类至Lua