POJ 2503 Babelfish(STL-map)
2016-07-27 20:36
381 查看
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 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
Sample Output
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;
}
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 40446 | Accepted: 17225 |
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;
}
相关文章推荐
- Crossed Ladders<poj2507题目一样>
- eclipse svn插件展示作者、修改日期等label
- c++内联函数(inline)使用详解
- ubunutu16.4 64位安装arm-linux-gcc交叉编译器
- LINUX下安装软件的集中方法
- codeforces 140C New Year Snowmen
- 2016暑假集训7.27 链表 数据结构上机测试1:顺序表的应用
- C# 创建ftp连接的时候报 System.Net.Sockets.SocketException] = {"不知道这样的主机。"}
- 完整java开发中JDBC连接数据库代码和步骤
- jenkins+maven+svn+tomcat之快速部署初探(docker篇)
- hdu2222 ac自动机模版
- diff命令
- HDU 5752 Sqrt Bo
- TortoiseSVN菜单项功能说明
- Leetcode 229. Majority Element II (Medium) (cpp)
- 20145202 《Java程序设计》第四周学习总结
- __bridge的相关使用
- python pandas 将行合并
- UVA 539 The Settlers of Catan
- linux 任务计划