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. Chi Square Distance

    The chi squared distance d(x,y) is, as you already know, a distance between two histograms x=[x_1,.. ...

  2. EIGamal密码体制

    EIGamal密码体制:由EIGamal提出,是一种基于离散对数问题的双钥密码体制,既可用于加密,又可以用于签名. 密钥对生成步骤: 1.取大素数p和g<p(g最好是p的素根) 2.选一整数x& ...

  3. linux - Mysql 创建用户和授权

    CREATE USER 'cui'@'%' IDENTIFIED BY 'xxxxxxxxxxxxxxxxxx'; GRANT ALL ON test_db.* TO 'cui'@'%'; REVOK ...

  4. 自己动手丰衣足食,h5手机端jquery弹窗插件(事件冒泡、单例模式、遮盖部分禁止默认滚动)

    感谢浏览,欢迎交流=.= 公司开发微信网页多处需要使用弹窗,使用jquery-ui的定制化下载仍需要150多kb,想来有些奢侈(最终下来只有11kb,压缩后2kb,啊,我的神), 手机端弹窗方式与pc ...

  5. [Leveldb源码剖析疑问]-block_builder.cc之Add函数

    Add函数是给一个Data block中添加对应的key和value,函数源码如下,其中有一处不理解: L30~L34是更新last_key_的,不理解这里干嘛不直接last_key_ = key.T ...

  6. 一分钟搭建Webpack+react+es6框架

    最近react刷屏的厉害,而随着它一起走进我们视野的还有webpack,webpack只是个工具,为什么如此火呢?因为简单好了不废话.   直接进入正题: 打开命令行工具: npm install - ...

  7. JS获取IP、MAC和主机名的五种方法

    javascript获取客户端IP的小程序,下面的代码是我在所有windowsNT5.0及以上的系统上都测试通过的,喜欢的朋友可以收藏下.今天在搞JS(javascript)获取客户端IP的小程序,上 ...

  8. WPF中将四个数字字符串值(比如:"10,10,300,300")转为Rect

    RectConverter rectConverter = new RectConverter(); string parseString = viewportEntry.Text; if (pars ...

  9. 用Python和Django实现多用户博客系统——UUBlog

    又过了一周,把代码整个的优化和完善了一下,也把TBlog更名为UUBlog.这次基本是把上次的整个更新了一下具体的功能大家可以下载后自己看看说一下主要的变化增加了频道表.博客表. 功能方面主要有增加频 ...

  10. Apple 公司开发者账号注册

    苹果公司开发者账号注册流程详解   这段时间在给朋友申请苹果账号,从个人开发者账号.公司账号到企业账号,申请了个遍.这里对申请流程做一下介绍,方便其他朋友,少走弯路,账号早日申请通过. 1.首先介绍下 ...