HDUOJ---What Are You Talking About
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others) Total Submission(s): 10963 Accepted Submission(s): 3521
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.
Author
Ignatius.L
map 容器的应用....map[aa]=bb;
STL;
代码:
1 #pragma warning (disable:4786)
2 #include<iostream>
3 #include<map>
4 #include<string>
5 #include<cstdio>
6 #include<cstring>
7 #include<cstdlib>
8 using namespace std;
9 const int maxn =3002;
10 char aa[maxn+1],bb[15];
11 int main()
12 {
13 scanf("%*s");
14 map<string,string>msg;
15 while(scanf("%s",aa),strcmp(aa,"END"))
16 {
17 scanf("%s",bb);
18 msg[bb]=aa;
19 }
20 scanf("%*s");
21 getchar();
22 map<string,string>::iterator it;
23 memset(bb,' ',sizeof(bb));
24 while(cin.getline(aa,3002),strcmp(aa,"END"))
25 {
26 int step=0;
27 for(int i=0;i<strlen(aa);i++)
28 {
29 if((aa[i]<'a'||aa[i]>'z'))
30 {
31 if(step)
32 {
33 it=msg.find(bb);
34 if(it!=msg.end())
35 {
36 cout<<(*it).second;
37 }
38 else
39 printf("%s",bb);
40 step=0;
41 memset(bb,' ',sizeof(bb));
42 }
43 cout<<aa[i];
44 }
45 else
46 {
47 bb[step++]=aa[i];
48 }
49 }
50 puts("");
51 }
52 return 0;
53 }
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 对于 JavaScript 中循环之间的技术差异概述
- 初识 webpack 原理——自定义插件
- 高性能解决线程饥饿的利器 StampedLock
- 前端应该知道的web调试工具——whistle
- 最强大的 CSS 布局 —— Grid 布局
- SAP Spartacus ProductConnector和ProductService实现
- Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】
- Redis 发布订阅,小功能大用处,真没那么废材!
- R语言实现生物序列的降维比对
- Tomcat NIO(9)-IO线程-Overall流程和关键类
- 有限元平面四边形等差单元python编程
- 动图演示:手撸堆栈的两种实现方法!
- [Go] 实战项目在线客服GO-FLY -在gin框架使用IP识别库转换IP为城市
- leetcode1552题解【二分+贪心】
- 这三年被分布式坑惨了,曝光十大坑