[SOJ] Babelfish
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 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 is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
Copy sample input to clipboarddog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay atcay
ittenkay
oopslay
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的更多相关文章
- 【贪心】SOJ 13983
SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...
- Babelfish(二分查找,字符串的处理略有难度,用sscanf输入)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28581 Accepted: 12326 题目链接: ...
- poj 2503:Babelfish(字典树,经典题,字典翻译)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 30816 Accepted: 13283 Descr ...
- POJ 2503 Babelfish
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28766 Accepted: 12407 Descripti ...
- Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36398 Accepted: 15554 Descripti ...
- Poj 2503 / OpenJudge 2503 Babelfish
1.Link: http://poj.org/problem?id=2503 http://bailian.openjudge.cn/practice/2503/ 2.Content: Babelfi ...
- POJ2503——Babelfish(map映射+string字符串)
Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...
- IC封装图片认识(二):SOP&SOJ
SOP SOP-EIAJ-TYPE-II-14L SSOP SSOP-16L TSOP(Thin Small Outline Package) TSSOP(Thin Shrink Outline Pa ...
- Babelfish(二分)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 37238 Accepted: 15879 Descr ...
随机推荐
- javascript转换.net DateTime方法 (比如转换\/Date(1426056463000)\/)
function getDate(str_time) { var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/'); va ...
- Django数据库迁移
如果你用过Django的数据库就会发现一个比较令人纠结的地方:数据库更改. 我们知道添加或者删除一个models.Model 需要在数据库里相应的操作,这需要我们进入数据库命令行手动添加或删除,因为s ...
- Push Notification总结系列(二)
Push Notification系列概括: 1.Push Notification简介和证书说明及生成配置 2.Push Notification的iOS处理代码和Provider详解 3.Push ...
- 学习ExpressionTree(做装配脑袋出的练习题)
1 // 第一题:画出下列表达式的表达式树.一开始,您很可能不知道某些操作其实也是表达式(比如取数组的运算符a[2]),不过没有关系,后面的习题将帮你验证这一点. //-a ParameterExpr ...
- 使用axis2访问webservice(webserivice基于.net平台实现)
webservice url=http://10.90.11.240:8081/ExceptionWebService.asmx?WSDL: 下载axis2组件,解压,进入bin目录,通过命令wsdl ...
- Make Things Move -- Javascript html5版(二)实现最基本的Sprite类和stage管理对象
现在这几篇写的都是比较基础的东西,有过相应开发经验的朋友可直接忽略啦. 计算机模拟的动画都是由很多静态的一连串影像(sprite)在一定帧率(fps)内逐帧播放出来的. 对于js来说,我们可以用提供的 ...
- mov sreg, r/m16 在16位和32位编程中的区别
总结于<X86汇编语言 从实模式到保护模式> 仅适用于X86系列处理器 1. 两者的区别: 例:mov ds, ax A.在指定16位编译模式下,产生的二进制码是 8E D8 B.在指定3 ...
- linux学习心得之vim/Cvim篇
linux学习心得之vim/Cvim篇 在linux 下,vim 时一种最常见的编辑器,很多linux的发行版就自带了.我的是CentOS 6.3. 基本上Vim共分为3种模式,分别是一般模式,编辑模 ...
- Mac下chrome的webapp hostadmin 快速切换host
首先是安装 app ,https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg ...
- 超详细LAMP环境搭建
一.准备工作 1.安装编译工具gcc.gcc-c++ 注意解决依赖关系,推荐使用yum安装,若不能联网可使用安装光盘做为yum源—— 1)编辑yum配置文件: # mount /dev/cdrom / ...