Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 44545   Accepted: 18803

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.
 
 

题意就是输入一堆字符串,左边的对应着右边的,然后下面给出右边的,让你输出来左边的。

输入字符串的时候,碰到空行就不再输入了。就用strlen就可以。

处理字符串的时候,在这里卡住了,后来解决了,靠strcmp,sscanf。

二分二分!!!

 
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+; struct node{
char s1[],s2[];
}a[N]; int n; int cmp(node a,node b){
return strcmp(a.s2,b.s2)<; //感觉好厉害(;´д`)ゞ
} int main(){
n=;
char str[];
while(gets(str)){
if(str[]=='\0') break;
sscanf(str,"%s%s",a[n].s1,a[n].s2); //好厉害(;´д`)ゞ
n++;
}
sort(a,a+n,cmp);
while(gets(str)){
int l=,r=n,mid,flag=;
while(l<=r){ //二分
mid=(l+r)>>;
if(strcmp(str,a[mid].s2)==){
printf("%s\n",a[mid].s1);
flag=;break;
}
else if(strcmp(str,a[mid].s2)<)
r=mid-;
else
l=mid+;
}
if(flag)
printf("eh\n");
}
return ;
}

POJ2503-Babelfish-二分的更多相关文章

  1. POJ2503——Babelfish(map映射+string字符串)

    Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...

  2. Babelfish(二分)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 37238   Accepted: 15879 Descr ...

  3. POJ2503 Babelfish map或者hash_map

    POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...

  4. POJ2503——Babelfish

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  5. POJ2503 Babelfish

    题目链接. 分析: 应当用字典树,但stl的map做很简单. #include <iostream> #include <cstdio> #include <cstdli ...

  6. POJ2503(Babelfish)--简单字典树

    思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en&q ...

  7. poj_2503(map映射)

    题目链接poj2503 Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 38820   Accepted: ...

  8. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  9. Babelfish(二分查找,字符串的处理略有难度,用sscanf输入)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28581   Accepted: 12326 题目链接: ...

  10. poj 2503 Babelfish(字典树或map或哈希或排序二分)

    输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...

随机推荐

  1. HTTP之URL分解

    HTTP使用统一资源标识符(Uniform Resource Identifiers, URI)来传输数据和建立连接.URL是一种特殊类型的URI,包含了用于查找某个资源的足够的信息 URL,全称是U ...

  2. which 命令详解

    一.which 作用: which 命令用于查找并显示给定命令的绝对路径,环境变量PATH中保存了查找命令时需要遍历的目录, which 命令会在环境变量$PATH 设置的目录里查找符合条件的文件.也 ...

  3. SQL Server授权购买简单介绍

    SQL Server授权购买简单介绍 之前有同事问我,使用盗版序列号的SQL Server到底有没有性能限制,之前本人一直没有深入研究过,后来经过一番资料搜集和查证,汇总成这篇文章 微软的SQL Se ...

  4. 《深入理解Java虚拟机:JVM高级属性与最佳实践》读书笔记(更新中)

    第一章:走进Java 概述 Java技术体系 Java发展史 Java虚拟机发展史 1996年 JDK1.0,出现Sun Classic VM HotSpot VM, 它是 Sun JDK 和 Ope ...

  5. C#winform自定义控件模拟设计时界面鼠标移动和调节大小、选中效果

    要想玩转Winform自定义控件需要对GDI+非常熟悉,对常用的控件有一些了解,好选择合适的基类控件来简化. 要点说明及代码 1)定义接口: using System; using System.Wi ...

  6. python基础(三)编码,深浅copy

    编码,深浅copy encode,decode在python2中使用的一些迷糊,python3中更容易理解 要理解encode和decode,首先我们要明白编码,字符和二进制的相关概念,简单来说,计算 ...

  7. bootstrap媒体查询

    Bootstrap 中的媒体查询允许您基于视口大小移动.显示并隐藏内容.下面的媒体查询在 LESS 文件中使用,用来创建 Bootstrap 网格系统中的关键的分界点阈值. /* 超小设备(手机,小于 ...

  8. Mysql查询不为null值

    Mysql本以为查询不为null就是!=null可是结果查询出来什么都没有,后来才发现不为null应该是is not null ,为null应该是is null.

  9. 如何将nupkg文件安装到VS2017

    本文为原创文章.源代码为原创代码,如转载/复制,请在网页/代码处明显位置标明原文名称.作者及网址,谢谢! 开发工具:VS2017 系统:Win10 X64 一.首先在https://www.nuget ...

  10. iOS QQ分享图片无反应问题

    受iOS 9 上 http 限制 需要在info.plist文件添加必要string <key>LSApplicationQueriesSchemes</key> <ar ...