POJ2503——Babelfish(map映射+string字符串)
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
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
Sample Output
cat
eh
loops
题目大意:
一本猫与人类语言的翻译字典,输入一个猫的语言,输出人的语言,若没有输出eh。
解题思路:
map映射水过。
Code:
/*************************************************************************
> File Name: poj2503.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年10月19日 星期日 16时54分07秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define MAXN 100000
using namespace std;
map <string,string> m;
void Solve()
{
char tmp1[];
string str1,str2;
while (gets(tmp1)&&strlen(tmp1))
{
int k=;
str1=str2="";
while ()
if (tmp1[k]==' ')
{
tmp1[k]='\0';
break;
}
else k++;
str1+=tmp1;
str2+=tmp1+k+;
m[str2]=str1;
}
while (cin>>str1)
if (m[str1].size())
cout<<m[str1]<<endl;
else
cout<<"eh"<<endl;
return ;
}
int main()
{
Solve();
return ;
}
POJ2503——Babelfish(map映射+string字符串)的更多相关文章
- POJ2503 Babelfish map或者hash_map
POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...
- Java Map获取key和value 以及String字符串转List方法
一.问题描述 这里描述两个问题: 1.Java Map获取key和value的方法: 2.String字符串转List的方法: 二.解决方法 1.Java Map获取key和value的方法 2. ...
- Map 集合 和 String 字符串相互转换工具类
package com.skynet.rimp.common.utils.util; import java.util.Arrays; import java.util.HashMap; import ...
- hdu 1075 map的使用 字符串截取的常用手段 以及string getline 使用起来的注意事项
首先说字符串的截取套路吧 用坐标一个一个的输入 用遍历的方式逐个去检查字符串中的字符是否为符合的情况 如果是的话 把该字符放入截取string 中 让后坐标前移 如果不是的话 截取结束 坐标初始化 然 ...
- fastjson在将Map<Integer, String>转换成JSON字符串时,出现中文乱码问题
fastjson在将Map<Integer, String>转换成JSON字符串时,出现中文乱码问题. 先记下这个坑,改天在看看是怎么导致的,暂时通过避免使用Integer作为键(使用St ...
- poj_2503(map映射)
题目链接poj2503 Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 38820 Accepted: ...
- map——映射(message.cpp)
信息交换 (message.cpp) [题目描述] Byteland战火又起,农夫John派他的奶牛潜入敌国获取情报信息. Cow历尽千辛万苦终于将敌国的编码规则总结如下: 1 编码是由大写字母组成的 ...
- Java精选笔记_集合【Map(映射)接口】
Map(映射)接口 简介 该集合存储键值对,一对一对的往里存,并且键是唯一的.要保证map集合中键的唯一性. 从Map集合中访问元素时,只要指定了Key,就能找到对应的Value. 关键字是以后用于检 ...
- Chat Order (map映射)
Chat Order Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit ...
随机推荐
- uva673 - Parentheses Balance(栈)
题意:1.空串合法.2.若A和B合法,则AB合法.3.若A合法,则(A)和[A]合法. 思路:遍历串,遇到(或[,则压入队列,若遇到),判断:若栈空,则不合法:若栈顶元素不是(,也不合法.]同理.因为 ...
- C++ sizeof操作符的用法和strlen函数的区别
摘要:本人首先介绍了C++中sizeof操作符的用法和注意事项,其次对比了和strlen的区别和使用,方便大家在写代码的时候查阅,和面试.笔试的时候复习. 目录: sizeof的用法: sizeof和 ...
- ThinkPHP3.2 加载过程(二)
回顾: 上次介绍了 ThinkPHP 的 Index.PHP入口文件.但只是TP的入口前面的入口(刷boss总是要过好几关才能让你看到 ,不然boss都没面子啊),从Index.PHP最后一行把我们引 ...
- 阅读《Oracle内核技术揭秘》的读书笔记
阅读<Oracle内核技术揭秘>,对oracle的内存结构.锁.共享池.undo.redo等整理成了如下的思维导图:
- 仿360手机卫士界面效果android版源码
仿360手机卫士界面效果android版,这个今天一大早在源码天堂的那个网站上看到了一个那个网站最新更新的一个源码,所以就分享给大学习一下吧,布局还挺不错的,而且也很简单的,我就不把我修改的那个分享出 ...
- IIS6,IIS7 最简单的重写URL
虽然现在很少用IIS6,今天突然要把项目搬到老的服务器上(IIS6),对项目还要重新部署一下. 主要把时间花在了对url的重写上.其实很简单,如下: IIS6 网站 → 属性 → 主目录 → 配置 → ...
- alter和alert的一些问题
今天在Java学习群里看到有人问:用alert能不能修改表结构?我第一反应是,alert是弹窗啊,怎么修改表结构?后来再看才知道,是那人打错了!我也晕了一下,还是记一下吧!alter是修改表结构的,a ...
- C++中执行windows指令
执行windows指令: BOOL ExecDosCmd(]) { SECURITY_ATTRIBUTES sa; HANDLE hRead,hWrite; sa.nLength = sizeof(S ...
- 第一个C++
输入:cin>>(相当于scanf) #include <iostream> using namespace std; int main() { int number; ...
- jQuery学习教程(1)
一.什么是jQuery JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safar ...