HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
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)的更多相关文章
- HDOJ/HDU 1200 To and Fro(加密解密字符串)
Problem Description Mo and Larry have devised a way of encrypting messages. They first decide secret ...
- 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 ...
- hdu 1075 What Are You Talking About 火星文翻译成英文
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- 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 ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
随机推荐
- 将选择的图片显示在listview中,并显示filename,path和type
if (openFileDialog1.ShowDialog() == DialogResult.OK) { listView1.Items.Clear(); string[] files = ope ...
- Yum安装Memcache
rpm -qa | grep libevent yum install libevent -y rpm -qa | grep memcached yum install memcached ...
- C语言学习总结(二) 运算流程
第三章.基本运算 (运算符.算数运算符.关系运算符.逻辑运算符.三目运算符.ASXLL码) 一.什么是运算符? 概念:是编译程序执行特定的算术或逻辑操作的符号: 分类:算术运算符. 关系运算符.逻辑运 ...
- 和阿木聊Node.js
npm:node.js官方库 cnpm:taobao维护的库: WebStorm:Node.js的开发工具,但是收费: seajs:还有一款交requirjs,前者是遵循amd规范(一次性参数中加载要 ...
- UIPageControll - 图片格式
设置pageCon的显示风格: 1. 颜色 page.pageIndicatorTintColor = [UIColor redColor]; page.currentPageIndicatorTin ...
- AFNetworking的原理与基本使用-b
全称是AFNetworking 虽然运行效率没有ASI高,但是使用比ASI简单 是对NSURLConnection和NSURLSession的各自的一层包装 AFN的内部中的RunLoop AFN内部 ...
- Unity给力插件之MegaFiers
这是一个关于网格变形的插件.其中有非常多的功能. 这是它的API地址:http://www.west-racing.com/mf/ 花了2天的时间实践并整理了其中绝大多数的功能,只有一些关于特殊格式的 ...
- C/S和B/S两种软件体系结构
目前两种流行的软件体系结构就是C/S和B/S体系结构,下面对两种体系结构进行一下总结: 1.C/S(客户端/服务器模式): 客户端和服务器都是独立的计算机,客户端是面向最终用户的应用程序或一些接口设备 ...
- JNI/NDK开发指南(一)—— JNI开发流程及HelloWorld
转载请注明出处:http://blog.csdn.net/xyang81/article/details/41777471 JNI全称是Java Native Interface(Java本地接口)单 ...
- bzoj 4066: 简单题 kd-tree
4066: 简单题 Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 234 Solved: 82[Submit][Status][Discuss] De ...