您的位置:首页 > 其它

POJ 2503 Babelfish(STL-map)

2016-07-27 20:36 381 查看
Babelfish

Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 40446 Accepted: 17225
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.

题意:就是上面一个字典,一个字符串对应一个字符串,后面给出一堆单词,问在字典中对应的单词是什么,并输出;没有就输出 eh

题解:map搞搞,不过G++会TLE,C++能过 (;′⌒`)

代码如下:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define maxn 100010
char str[20],s[20],word[20];
int main()
{
map<string,bool>appear;
map<string,string>translate;
int i;
while(1)
{
char t;
t=getchar();
if(t=='\n')
break;
else
{
str[0]=t;
i=1;
while(1)
{
t=getchar();
if(t==' ')
{
str[i]='\0';
break;
}
str[i++]=t;
}
}
scanf("%s",s);
getchar();
appear[s]=true;
translate[s]=str;
}
while(scanf("%s",word)!=EOF)
{
if(appear[word])
cout<<translate[word]<<endl;
else
printf("eh\n");
}
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: