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 数组属性和方法
- PostgreSQL VFD机制
- POJ 2136 Vertical Histogram(当时写的比较恶心,优化一下)
- PostgreSQL 12的可拔插存储引擎--表访问方法以及bloackholes案例
- POJ 2230 Watchcow 欧拉回路的DFS解法(模板题)
- POJ 2188 Cow Laundry
- 51NOD 2072 装箱问题 背包问题 01 背包 DP 动态规划
- 51 NOD 1049 最大子段和 动态规划 模板 板子 DP
- 51NOD 1006 最长公共子序列 Lcs 动态规划 DP 模板题 板子
- CodeForces - 262C 贪心
- 花狗C语言彩色贪吃蛇(完整代码)
- CodeForces - 262B
- CodeForces - 260B
- 蓝桥杯第九届C语言C组第一题:哪天返回
- java学习之路:17.掌握Boolean对象的创建以及Boolean类提供的各种方法
- java学习之路:16.掌握Integer,Long,Short对象的创建以及其类提供的各种方法