POJ 2503 Babelfish(map)

Babelfish

题目传送门~

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 56564   Accepted: 23224

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

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

Sample Output

cat
eh
loops

Hint

Huge input and output,scanf and printf are recommended.

Source

Waterloo local 2001.09.22


哈哈哈哈哈哈看!第一道POJ我好菜呜呜呜呜...不过我会努力的,冲啊啊啊啊AClusir


AC后两句话:

①这题我切掉后看了好多思路,感觉有一个思路用getchar一个个读的也超级好!!!附上大哥的传送门!

②然后这题很简单嘛...其实就是让你搞个字典然后查一下,map一下就完事了~(hhhhh昨天看郎朗的综艺东北话完事了xs)

③这题输入的组织很重要哇,我是用的gets一起搞进来,再用sscanf分开,超级省事。(不然就要注意空格然后整成两个循环,大家看情况,这题个人觉得考编程的,思路不难叭)

④大家可以学习一下sscanf(博客很多),我记得我学的时候看到过就注意了一下,现在就用到啦~人生没有白走的路,每一步都算数!!!(以后有机会我写个教程,然后你懂得...关注一下你不就学会了嘛嘻嘻嘻嘻)


话不多说,上才艺!!!

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

map<string,string> dic;//map字典 

int main()
{
	char pre[12],suf[12],str[24];//定义键值对字符数组和输入所需要的变量
	while(gets(str)&&str[0]!='\0'){
		sscanf(str,"%s %s",suf,pre);//按序读取str,注意中间的空格以及sscanf用法 
		dic[pre]=suf;
	}
	while(gets(str)&&str[0]!='\0'){
		if(dic.count(str))  cout<<dic[str]<<endl;
		else  cout<<"eh"<<endl;		
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43838723/article/details/106600598
今日推荐