Kattis - Babelfish

Babelfish

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 100000100000 dictionary entries, followed by a blank line, followed by a message of up to 100000100000 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 non-empty sequence of at most 1010lowercase 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 1 Sample Output 1
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay
cat
eh
loops

题意

前面那部分是字典里的,后面就查找给出的字符串有没有属于前面的字典里,有的话就输出那个单词

思路

用map存就行了

代码

#include<bits/stdc++.h>
using namespace std;
map<string,string> m;
int main(){
    string line,a,b;
    while(getline(cin,line)&&line!=""){
        stringstream s(line);//格式转换
        s>>a;
        s>>b;
        m[b]=a;
    }
    while(cin>>b){
        a=m[b];
        cout<<(a==""?"eh":a)<<endl;
    }
}
时间: 2024-12-12 23:04:20

Kattis - Babelfish的相关文章

POJ 2503 Babelfish (Trie树 或 map)

Babelfish Time Limit: 3000MS        Memory Limit: 65536K Total Submissions: 34278        Accepted: 14706 Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately

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

Kattis - Association for Computing Machinery

Association for Computing Machinery ACM (Association for Computing Machinery) organizes the International Collegiate Programming Contest (ICPC) worldwide every year. In the ICPC, a team of three students is presented with a problem set that contains 

Babelfish(二分)

Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 37238   Accepted: 15879 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(字典树)

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

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

Kattis downtime

链接:https://open.kattis.com/problems/downtime 题意:n个要解决的进程,每个服务器可以解决k个进程,每个进程花费1000MS,给出n个进程的开始时间,问最少要几个服务器 思路:我们可以求出每个进程的区间,然后看我们可以不重叠的解决多少个进程 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 struct node{ 5 int x; 6 int y; 7 }a[200005]; 8 bool cm

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

POJ2503 Babelfish

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