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
 Copy sample input to clipboard
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay atcay
ittenkay
oopslay
Sample Output
cat
eh
loops
#include<stdio.h>
#include<string.h>
#include<stdlib.h> char chip[100001][15];
char bhip[100001][15];
int idex[100001];
char w[15];
int L,yes; int cmp(const void *a,const void *b) //qsort函数要求的比较函数,函数参数列表必须如此
{
return strcmp(bhip[*(int *)a],bhip[*(int *)b]); //如果a比b大,则返回正数
} int main()
{
int i,j,k,t;
L=0; while(gets(w)&&w[0]!='\0')
{
sscanf(w,"%s %s",chip[L],bhip[L]);
idex[L]=L;
L++;
} qsort(idex,L,sizeof(idex[0]),cmp);//按字典顺序进行快速排序,cmp为排序的方法 while(gets(w))//字典查找方法进行二分查找
{
i=0;
j=L-1;
yes=0;
while(i<=j)
{
k=(i+j)/2;
t=strcmp(bhip[idex[k]],w);
if(t>0)
{
j=k-1;
}
else if(t<0)
{
i=k+1;
}
else
{
yes=1;
break;
} }
if(yes==1)
printf("%s\n",chip[idex[k]]);
else
{
printf("eh\n");
} } return 0;
}

  

[SOJ] Babelfish的更多相关文章

  1. 【贪心】SOJ 13983

    SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...

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

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

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

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

  4. POJ 2503 Babelfish

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

  5. Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏

    Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36398 Accepted: 15554 Descripti ...

  6. Poj 2503 / OpenJudge 2503 Babelfish

    1.Link: http://poj.org/problem?id=2503 http://bailian.openjudge.cn/practice/2503/ 2.Content: Babelfi ...

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

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

  8. IC封装图片认识(二):SOP&SOJ

    SOP SOP-EIAJ-TYPE-II-14L SSOP SSOP-16L TSOP(Thin Small Outline Package) TSSOP(Thin Shrink Outline Pa ...

  9. Babelfish(二分)

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

随机推荐

  1. [置顶] 博客停止更新 && 我的大学数年

    博客停止更新 前言: 这些天,一直还没有时间发表这篇博文,近期,做了一个决定:博客更新停止. 我有话说: 这些天来,还真是感谢大家的关注了.从2011年的07至今,2013年的07月,两个年头,写下了 ...

  2. Nginx+Tomcat+Memcached实现tomcat集群和session共享

    一.Nginx安装 详见前文:http://www.cnblogs.com/yixiwenwen/p/3574097.html 二.memcached安装和启动 详见前文:http://www.cnb ...

  3. Redis集群方案

    Redis集群方案 前段时间搞了搞Redis集群,想用做推荐系统的线上存储,说来挺有趣,这边基础架构不太完善,因此需要我们做推荐系统的自己来搭这个存储环境,就自己折腾了折腾.公司所给机器的单机性能其实 ...

  4. 【Hook技术】实现从"任务管理器"中保护进程不被关闭 + 附带源码 + 进程保护知识扩展

    [Hook技术]实现从"任务管理器"中保护进程不被关闭 + 附带源码 + 进程保护知识扩展 公司有个监控程序涉及到进程的保护问题,需要避免用户通过任务管理器结束掉监控进程,这里使用 ...

  5. iOS app 发布错误 ERROR ITMS-90167: "No .app bundles found in the package"

    今天iOS 上传 APP 突然发生了这个错误,在排查非证书错误后感到非常奇怪, 因为昨天刚刚上传了另一个APP,一切正常. 仔细回忆了下 昨天和今天唯一的不同就是我升级了 电脑操作系统至 macOS ...

  6. iphone手机用wireshark抓包

    ios连上电脑 查看udid. 启动虚拟接口 rvictl -s 7e65eeaa55a1e43dbdfb44a02f9871f1f304043e 打开mac权限 sudo chmod 644 /de ...

  7. springMVC3学习(一)--框架搭建

    由于项目需要,学习下springMVC,在此简单记录一下. 如有十万个为什么,暂且忽略,待以后研究. 本人是基于3.1.1版本开发,如遇jar包版本冲突等其他问题,概不负责. 下载地址:上传此zip资 ...

  8. HTTP header 介绍

    HTTP(Hyper Text Transfer Protocol)是超文本传输协议的缩写,它用于传送www方式的数据.HTTP协议采用了请求/响应模型.客服端向服务器发送一个请求,请求头包含请求的方 ...

  9. 设置 Ext.data.Store 传参的请求方式

    设置 Ext.data.Store 传参的请求方式 1.extjs 给怎么给panel设背景色 设置bodyStyle:'background:#ffc;padding:10px;', var res ...

  10. BCP导入导出MsSql

    BCP导入导出MsSql 1.导出数据 (1).在Sql Server Management Studio中: --导出数据到tset1.txt,并指定本地数据库的用户名和密码 --这里需要指定数据库 ...