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.

题意:

给出一个“翻译-原文”的对应表,然后给出句子,要把句子中的原文都翻译出来。

如果不是字母,就原样输出~

开始因为空格问题、PE了几次~~

用Map秒过~~

考虑的时候一行一行的考虑~

一行一行的输出~

注意读取第一个END后面的回车~

用nextLine();

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner; /**
* @author 陈浩翔
*
* 2016-5-26
*/
public class Main{ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
Map<String, String> map = new HashMap<String, String>();
String str1 = "";
String str2 = "";
while (true) {
str1 = sc.next();
if ("START".equals(str1)) {
continue;
}
if ("END".equals(str1)) {
break;
}
str2 = sc.next();
map.put(str2, str1);
} sc.nextLine();
String s = "";
while (true) {
s = sc.nextLine();
if ("START".equals(s)) {
continue;
}
if ("END".equals(s)) {
break;
}
String str = "";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
str += s.charAt(i); if(i==s.length()-1){
String v = map.get(str);
if (v != null) {
System.out.print(v);
} else {
System.out.print(str);
}
str="";
}
} else {
String v = map.get(str);
if (v != null) {
System.out.print(v);
} else {
System.out.print(str);
}
System.out.print(s.charAt(i));
str="";
}
}
System.out.println();
} }
}
}

HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)的更多相关文章

  1. HDOJ/HDU 1200 To and Fro(加密解密字符串)

    Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secret ...

  2. HDU 1075 What Are You Talking About (stl之map映射)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  3. hdu 1075 What Are You Talking About 火星文翻译成英文

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  4. HDU 1075 What Are You Talking About(Trie的应用)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  5. HDOJ(HDU).1412 {A} + {B} (STL SET)

    HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...

  6. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  7. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

  8. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

  9. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

随机推荐

  1. Headfirst设计模式的C++实现——简单工厂模式(Simple Factory)

    Pizza.h #ifndef _PIZZA_H #define _PIZZA_H #include <iostream> #include <string> class Pi ...

  2. nagios 完全配置手册

    Linux下Nagios的安装与配置   一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机 ...

  3. Uniqueidentifier数据类型

    一.Uniqueidentifier数据类型 可存储16字节的二进制值 Uniqueidentifier用来存储一个全局唯一标识符,即GUID.GUID是唯一的二进制数:世界上的任何两台计算机都不会生 ...

  4. kindeditor编辑器代码过滤解决方法.

    很多朋友在使用Kindeditor编辑器的时候都会遇到这样一个问题,如:给A标签加上title属性过后,浏览的时候,却神奇般地发现title属性没有了.再次切换html源代码的时候,返现编辑器将tit ...

  5. python学习_数据处理编程实例(一)

    目的:用一个实例总结学习到的with语句,函数,列表推导,集合,排序,字符分割等内容 要求:分别以james,julie,mikey,sarah四个学生的名字建立文本文件,分别存储各自的成绩,时间格式 ...

  6. poj 3185 The Water Bowls

    The Water Bowls 题意:给定20个01串(最终的状态),每个点变化时会影响左右点,问最终是20个0所需最少操作数? 水题..直接修改增广矩阵即可:看来最优解不是用高斯消元(若是有Gaus ...

  7. 查看用户列表在Linux

    Linux下查看用户列表   原文地址:http://xiaod.in/read.php?77 俺的centos vps上面不知道添加了多少个账户,今天想清理一下,但是以前还未查看过linux用户列表 ...

  8. iOS开发者计划(转)

    苹果对软件和开发者的管理十分严格,你只有加入了Apple Developer计划之后,才能将你的软件放到真机上运行或者发布到App Store上去.这种方法看似麻烦,但是却有效的解决了盗版和劣质软件充 ...

  9. SQL Express几个版本的区别

    对于这三个文件:SQLEXPR32_x86_CHS.exe.SQLEXPR_x86_CHS.exe. SQLEXPR_x64_CHS.exe,大家一看就知道是sqlserver的express版本,但 ...

  10. Aircrack-ng官方文档翻译[中英对照]---Airdecap-ng

    Aircrack-ng官方文档翻译---Airdecap-ng   Description[简介] With airdecap-ng you can decrypt WEP/WPA/WPA2 capt ...