Nameless Site

But one day, you will stand before its decrepit gate,without really knowing why.

0%

Babelfish

来源POJ第2503题

Description

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as “eh”.

Sample Input

1
2
3
4
5
6
7
8
9
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

1
2
3
cat
eh
loops

Hint

Huge input and output,scanf and printf are recommended.

Map

提示方案上说可用二分查找啥的,但是懒人直接当HashMap水题,直接过了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;

public class Main {

public static void main(String[] args) {
Map<String,String> map = new HashMap<String, String>();
Scanner in = new Scanner(System.in);
String input;
String key,value;
int index;
while (!(input = in.nextLine()).equals("")){
index = input.indexOf(' ');
key = input.substring(0,index);
value = input.substring(index + 1,input.length());
map.put(value,key);
}
while (!(input = in.nextLine()).equals("")){
if(map.containsKey(input)){
System.out.println(map.get(input));
}else{
System.out.println("eh");
}
}
}
}