POJ 2503 Babelfish (STL)
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
分析:
给定一些单词以及每个单词对应的意思,这之间是一一对应的。然后询问某一个单词对应的意思是什么,如果有对应的意思的话,就把对应的意思输出来,否则输出“eh”。
代码:
#include <iostream>
#include <string>
#include <map>
#include<stdio.h>
using namespace std;
map <string,string>mp;
int main ()
{
char ch[30],str1[15],str2[15];
while (gets(ch))
{
if (ch[0]==0)
break;
sscanf(ch,"%s%s",str1,str2);
mp[str2]=str1;
}
while (gets(ch))
{
map<string,string>::iterator it;
it=mp.find(ch);
if (it!=mp.end())
cout<<(*it).second<<endl;
else
printf("eh\n");
}
return 0;
}
POJ 2503 Babelfish (STL)的更多相关文章
- 题解报告:poj 2503 Babelfish(map)
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...
- poj 2503:Babelfish(字典树,经典题,字典翻译)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30816 Accepted: 13283 Descr ...
- poj 2503 Babelfish(字典树哈希)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 29059 Accepted: 12565 Description You hav ...
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- POJ 3414 Pots(罐子)
POJ 3414 Pots(罐子) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 You are given two po ...
- POJ 3281 Dining (网络流)
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...
- POJ 1847 Tram (最短路径)
POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and ra ...
- C++标准模板库(STL)和容器
1.什么是标准模板库(STL)? (1)C++标准模板库与C++标准库的关系 C++标准模板库其实属于C++标准库的一部分,C++标准模板库主要是定义了标准模板的定义与声明,而这些模板主要都是 类模板 ...
随机推荐
- 洛谷P3588 [POI2015]PUS
题面 sol:说了是线段树优化建图的模板... 就是把一整个区间的点连到一个点上,然后用那个点来连需要连一整个区间的点就可以了,就把边的条数优化成n*log(n)了 #include <queu ...
- Dictionary字典
泛型,键值对 Dictionary<int,string> dic=new Dictionary<int,string>(); dic.Add(,"张三") ...
- ref、out与params
ref 把值传递转换为引用传递,侧重于将一个值带到函数中进行改变,再将改变后的值带出去,ref参数在函数外必须为ref参数赋值 ; AddSalary(ref salary); //如果不写ref,s ...
- Django-website 程序案例系列-5 模态对话框实现提交数据
html代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- BZOJ3417[Poi2013]Tales of seafaring——BFS
题目描述 Young Bytensson loves to hang out in the port tavern, where he often listens to the sea dogs te ...
- 洛谷 P1430 序列取数 解题报告
P1430 序列取数 题目描述 给定一个长为\(n\)的整数序列\((n<=1000)\),由\(A\)和\(B\)轮流取数(\(A\)先取).每个人可从序列的左端或右端取若干个数(至少一个), ...
- bzoj1597/luogu2900 土地购买 (斜率优化dp)
首先按x从小到大排序,那么可得: f[i]=min{f[j]+x[i]*maxy[j+1..i]} 然而这样是$O(n^2)$的而且无法做优化. 然后我们考虑:如果对于某一点,存在另一点的x和y都比它 ...
- Java -- JDBC 学习--通过 ResultSet 执行查询操作
ResultSet: 结果集. 封装了使用 JDBC 进行查询的结果. 1. 调用 Statement 对象的 executeQuery(sql) 可以得到结果集. 2. ResultSet 返回的实 ...
- P3747 相逢是问候 欧拉定理+线段树
巨难!!! 去年六省联考唯一的一道黑牌题,我今天一天从早到晚,把它从暴力15分怼到了90分,极端接近正解了. bzoj上A了,但是洛谷和loj上面就不行.伪正解会T,奇奇怪怪的类正解会WA.. 那么, ...
- JAVA8给我带了什么——Optional和CompletableFuture
不管是JAVA,还是.NET.我们常常会看到空异常(NullPointerException).这种异常都是在运行的过程中出现.往往是变量是一个null值.但是你引用这个变量的后继字段或是方法.所以我 ...