UVa 10282 / POJ 2503 Babelfish / ZOJ 1109 Language of FatMouse (STL&map)

10282 - Babelfish

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1223 http://poj.org/problem?id=2503

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1109
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 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 is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Output for Sample Input

cat
eh
loops

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
使用map。
注意中间空行读取时s[0]=0(这是因为gets在读取完一行后跳过'\n'但并未保存'\n',所以s[0]='\0'=0)
 
 
 
 
 
 
完整代码:
/*UVa: 0.399s*/
/*ZOJ: 180ms,15824KB*/

#include<cstdio>
#include<string>
#include<map>
using namespace std;

char s[25], a[15], b[15];
map<string, string> m;

int main()
{
	while (gets(s), s[0]) sscanf(s, "%s%s", a, b), m[string(b)] = string(a);
	while (gets(s)) puts(m.find(s) != m.end() ? m[s].c_str() : "eh");
	return 0;
}

 
 
 

你可能感兴趣的:(数据结构,ACM,结题报告,查找树)