码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2503 哈希 Map

时间:2015-08-21 13:46:24      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 36967   Accepted: 15749

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

//16096K 2625MS
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>

using namespace std;

int main()
{
	char s[100],s1[11];
	string ss;
	char c;
	map<string,string>Q;
	int num;
	while(gets(s)&&s[0]!='\0')  //读串比读多个字符快
	{
		int len=strlen(s);
		int i;
		for( i=0;i<len;i++)
		{
			if(s[i]==' ')
			{s[i]='\0';
			 break;
			}
		}
		ss=s+i+1;
		Q[ss]=s;
	}
	while(~scanf("%s",s1))
	{
		if(Q[s1].size())
			cout<<Q[s1]<<endl;
		else
			printf("eh\n");
	}
}
//	while(~scanf("%c",&c))  // 超时
//	{
//		if(c=='\n')
//			break;
//		num=0;
//		while(c!=' ')
//		{
//			s[num++]=c;
//			scanf("%c",&c);
//		}
//		s[num]='\0';   //够成字符串
//		num=0;
//		scanf("%c",&c);  //防止上一个空格被读入
//
//		while(c!='\n')
//		{
//			ss[num++]=c;
//			scanf("%c",&c);
//		}
//		ss[num]='\0';
//		Q[ss]=s;
//	}


版权声明:本文为博主原创文章,未经博主允许不得转载。

poj 2503 哈希 Map

标签:

原文地址:http://blog.csdn.net/became_a_wolf/article/details/47831789

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!