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++标准模板库主要是定义了标准模板的定义与声明,而这些模板主要都是 类模板 ...
随机推荐
- Java之Date Time API (Java 8 新特性)
Java 8 – Date Time API Java 8 comes with a much improved and much required change in the way date an ...
- VMware下Centos7快速搭建vsftpd
最简单快捷的实现ftp的功能,不考虑安全问题. 1.配置防火墙和selinux vi /etc/selinux/config # This file controls the state of SEL ...
- python成长之路七-函数的进阶
1,python中,名称空间分三种: 全局命名空间 局部命名空间(临时命名空间) 内置名称空间 2,作用域(两种): 1,全局作用域 包含:全局名称空间 内置名称空间 2,局部作用域 包含:局 ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)
描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...
- Android GPS定位测试(附效果图)
今天因为工作需要,把以前编写的一个GPS测试程序拿出来重新修改了一下.这个程序说起来有些历史了,是我11年编写的,那时候学了Android开发没多久,算是一个实验性的作品.现在工作需要,重新拿出来修整 ...
- bzoj1691/luogu2869 [USACO07DEC]挑剔的美食家 (STL::set)
给牛和草都按价格排序,然后贪心地把草给牛(就是尽量给满足价格的.要求的美味度最高但不超过这个草的美味度的牛) 这个可以用一个平衡树来维护,偷懒直接用multiset了 #include<bits ...
- 设计模式 (二)——观察者模式(Observer,行为型)
1.概述 使用设计模式可以提高代码的可复用性.可扩充性和可维护性.观察者模式(Observer Pattern)属于行为型模式,在对象之间定义一对多的依赖,这样一来,当一个对象改变状态,依赖它的对象都 ...
- 11:SSM框架下各个层的解释说明
具体见网址:http://blog.csdn.net/lutianfeiml/article/details/51864160
- MATLAB:图像的与、或、非、异或逻辑运算(&、|、~、xor)
图像的与.或.非.异或逻辑运算涉及到了&.|.~和xor符号 close all;%关闭当前所有图形窗口,清空工作空间变量,清除工作空间所有变量 clc; clear all; I=imrea ...
- Java逐行写入字符串到文件
下边是写东西到一个文件中的Java代码.运行后每一次,一个新的文件被创建,并且之前一个也将会被新的文件替代.这和给文件追加内容是不同的. 1. public static void writeFile ...