poj2503

Babelfish

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 39585   Accepted: 16891

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

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
using namespace std;
map<string,string>m;
char s[30],x[11],y[11];
int main(){
    while(1){
        gets(s);
        if(s[0]==‘\0‘) break;
        sscanf(s,"%s %s",x,y);//分割
        m[y]=x;
    }
    while(gets(y)){
        if(m[y]=="") cout<<"eh"<<endl;
        else cout<<m[y]<<endl;
    }
    return 0;
}
时间: 2024-12-28 04:39:26

poj2503的相关文章

POJ2503——Babelfish(map映射+string字符串)

Babelfish DescriptionYou 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.InputInput consists of up to 100,000 diction

POJ2503 Babelfish map或者hash_map

POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string.h> #include<cmath> #include<vector>

POJ2503:Babelfish(二分)

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

POJ2503 Babelfish

问题链接:POJ2503 Babelfish. 这个问题只是一个字典问题,自然用map来实现.问题的关键是时间上能否更快. 本来是想用类unordered_map(采用哈希搜索的map)来编写程序,编译不支持,只好改为map. 这个问题用类unordered_map来编写程序,时间上会更快一些,也更为合理. AC通过程序如下: /* POJ2503 Babelfish */ #include <iostream> #include <string> //#include <u

poj2503(Babelfish)

题目地址:Babelfish 题目大意: 你将要迁徙一个大城市里,但是你们的语言不一样.但是幸运的是你有一本字典,通过你的字典可以翻译外国的语言.每一行先是字典的单词接着是外国语言.  字典输完,给你几个外国语言,输出字典的单词否则输出“eh”. 解题思路: map将每一行的单词mp一个整数,这整数可以是序列号,这样你找到对应的mp数值就很容易输出.注意输入输出即可. 代码: 1 #include <algorithm> 2 #include <iostream> 3 #inclu

poj2503 Babelfish BKDRhash+链式hash

题目链接 题意:给定字符串以及对应的字符串,再给字符串找到对应的字符串,不存在输出"eh". 思路:造模板. /********************************************************* file name: poj2503.cpp author : kereo create time: 2015年04月12日 星期日 17时13分12秒 ******************************************************

POJ-2503 Babelfish---map或者hash

题目链接: https://vjudge.net/problem/POJ-2503 题目大意: 就像查找一本字典,根据输入的条目和要查询的单词,给出查询结果(每个单词长度不超过10) 解题思路: map容器可以直接过,不过为了练习hash,写了个hash也可以过 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<string> 5 #include<map>

POJ2503(hash)

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

字符串哈希之ELFHash,poj2503

#include <iostream> #include<cstdio> #include<cstring> using namespace std; const int M = 149993; typedef struct { char e[11]; char f[11]; int next; }Entry; Entry entry[M]; int i = 1; int hashIndex[M];//哈希表 int ELFHash(char *key) { unsig