首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【POJ】2503 - Babelfish(STL)

【POJ】2503 - Babelfish(STL)

作者头像
FishWang
发布2025-08-26 19:55:21
发布2025-08-26 19:55:21
1540
举报

点击打开题目

Babelfish

Time Limit: 3000MS

Memory Limit: 65536K

Total Submissions: 40350

Accepted: 17188

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

代码语言:javascript
复制
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

代码语言:javascript
复制
cat
eh
loops

Hint

Huge input and output,scanf and printf are recommended.

Source

Waterloo local 2001.09.22

纯纯的 STL 之string、map 的应用题。

在读入数据方面要注意,我不是很会用C++的输入输出流,方法比较笨。

代码如下:

代码语言:javascript
复制
#include <cstdio>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	map<string,string> dic;
	string a,b;
	char t;
	char temp[22];
	while (t = getchar())
	{
		if (t == '\n')
			break;
		a.clear();
		a += t;
		scanf ("%s",temp);
		a += temp;
		scanf ("%s",temp);
		b.clear();
		b += temp;
		dic[b] = a;
		getchar();
	}
	while (~scanf ("%s",temp))
	{
		a.clear();
		a += temp;
		if (dic[a] != "")
			cout << dic[a] << endl;
		else
			cout << "eh" << endl;
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档