poj 2503 哈希 Map

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;
//	}

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

时间: 2024-11-09 00:41:22

poj 2503 哈希 Map的相关文章

poj 2503 哈希 Map 字典树

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

poj 2503 Babelfish (map,trie 树)

链接:poj 2503 题意:输入 语言A及翻译为语言B的词典,之后再输入语言B的单词,判断是否能从词典中找到, 若能找到,将其翻译为语言A,否则输出"eh". 思路:这题肯定得先将词典对应语言存起来,但是如果直接暴力找输入的单词是否出现过,必然会TLE 因为单词都是一对一的关系,可以用map实现 当然,trie树是用空间换时间,对于字符串的查找,在时间上有着相当的优势,因此也可以用trie树 注:sscanf函数,从一个字符串中读进与指定格式相符的数据. map实现:938MS #i

POJ 2503 Babelfish(map入门)

题目链接:http://poj.org/problem?id=2503 代码: #include<cstdio> #include<string> #include<map> #include<iostream> using namespace std; int main(void){ char english[11],foreign[11]; map<string,bool>appear; //记录foreign与english的配对映射是否出

题解报告:poj 2503 Babelfish(map)

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 ent

POJ 2503 字典树

这题记得以前是我们周赛的题,然后用的是map,也暴过了. 因为这两天要给大一的讲字典树,所以练练几道的代码,以防给大一搞晕了-- #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<queue> #include<set> #include<cmath> #include

字典树模板题 POJ 2503

1 #include <cstdio> 2 #include <cstring> 3 4 char en[11],fr[11]; 5 int st; 6 struct Tire{ 7 int next[26]; 8 char eng[11]; 9 }node[200005]; 10 void insert(char *s,int cur) 11 { 12 if(*s){ 13 if(!node[cur].next[*s-'a']) 14 node[cur].next[*s-'a']

poj 2503:Babelfish(字典树,经典题,字典翻译)

Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 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

HLG 1808 绘画 (哈希 + map + 线段树)

链接: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1808 Description 小胖子最近喜欢上了画画,但是他的画画技术很差,只能从零开始,小胖子在一条线上画了很多彩色的球,但是觉得不好看,就想修改. 小胖子站在画前想了又想,他有时会将一些连续的点涂成相同的颜色.但他感觉累的时候,就会无聊的数数某个颜色在某段区间内出现的次数. Input 每组数据的第一行输入两个正整数n和m(1&l

POJ 3087-Shuffle&#39;m Up(map+模拟)

题目地址:POJ 3087 题意:已知两堆牌数均为n的纸牌堆a和b的初始状态, 按给定规则能将他们相互交叉组合成一堆牌str,再将str的最底下的n张牌归为a,最顶的n张牌归为b,依此循环下去.现在输入a和b的初始状态 以及 预想的最终状态c,问a, b经过多少次洗牌之后,最终能达到状态c,若永远不可能相同,则输出"-1". 思路:用map记录一下当前str出现的状态,如果当前的str在前面出现过,那就输出-1,因为无论怎么变换都不会出现终态c.若果没有出现的话就继续洗牌然后分牌,一直