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 ;
}

POJ 2503.Babelfish-sscanf()函数+strcmp()函数+二分的更多相关文章

  1. (查找函数+atoi)判断与(注册函数+strcmp函数)判断两种方法

    loadrunner中接口判断的2中方法    如下: 1. ●查找函数web_reg_find() ● atoi():将字符串转换为整型值 作比较  > 0 Action() { //检查点函 ...

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

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

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

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

  4. poj 2503 Babelfish(Map、Hash、字典树)

    题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...

  5. 题解报告:poj 2503 Babelfish(map)

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

  6. poj 2503:Babelfish(字典树,经典题,字典翻译)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 Descr ...

  7. poj 2503 Babelfish (查找 map)

    题目:http://poj.org/problem?id=2503 不知道为什么 poj  的 数据好像不是100000,跟周赛的不一样 2000MS的代码: #include <iostrea ...

  8. poj 2503 Babelfish(字典树哈希)

    Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 29059 Accepted: 12565 Description You hav ...

  9. POJ 2503 Babelfish

    Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28766 Accepted: 12407 Descripti ...

随机推荐

  1. arc068 E: Snuke Line

    首先要知道 (m/1 + m/2 + ... + m/m) 约为 mlogm 还有一个比较明显的结论,如果一个纪念品区间长度大于d,那么如果列车的停车间隔小于等于d,则这个纪念品一定能被买到 然后把区 ...

  2. hbase(0.94) get、scan源码分析

    简介 本文是需要用到hbase timestamp性质时研究源码所写.内容有一定侧重.且个人理解不算深入,如有错误请不吝指出. 如何看源码 hbase依赖很重,没有独立的client包.所以目前如果在 ...

  3. [学习笔记]最小割之最小点权覆盖&&最大点权独立集

    最小点权覆盖 给出一个二分图,每个点有一个非负点权 要求选出一些点构成一个覆盖,问点权最小是多少 建模: S到左部点,容量为点权 右部点到T,容量为点权 左部点到右部点的边,容量inf 求最小割即可. ...

  4. 【NOIP 模拟赛】Evensgn 剪树枝 树形dp

    由于树规做的少所以即使我考试想出来正确的状态也不会转移. 一般dp的转移不那么繁杂(除了插头.....),即使多那也是清晰明了的,而且按照树规的一般思路,我们是从下到上的,所以我们要尽量简洁地从儿子那 ...

  5. 在Eclipse上使用egit插件通过ssh协议方式上传项目代码的具体步骤

    在Eclipse上使用egit插件通过ssh协议方式上传项目代码 前戏: 使用ssh方式可以不通过https协议,避免直接提供账号密码的方式上传项目到git在线服务器,如Bitbucket.GitHu ...

  6. React & Redux 的一些基本知识点

    一.React.createClass 跟 React.Component 的区别在于后者使用了ES6的语法,用constructor构造器来构造默认的属性和状态. 1. React.createCl ...

  7. 新手如何更换自己喜欢的背景以及此背景的css码

    以下内容为转载(对于css码可以自己写当然也可以去网上搜现成的): 更换背景教学:https://jingyan.baidu.com/album/fc07f9897c730412ffe519c0.ht ...

  8. 转:Spring-session & redis 子域名共享session

    Spring-session & redis 子域名共享session 例子: a.example.com b.example.com spring 版本 4.2.6.RELEASE Spri ...

  9. Exceptioninthread"main"java.lang.ClassNotFoundsException的问题

    报错如下: Exceptioninthread"main"java.lang.ClassNotFoundsException 大致可以判断出是无法定位到main方法,应该是用mav ...

  10. [HNOI2015]部分题解

    Day1 T2 [HNOI2015]接水果 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果.由于她已经DT FC 了The big black,  她觉得这个游戏太简单了, ...