[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 ...
随机推荐
- OWC11生成统计图案例
(1)饼状图:----通过修改参数生成不同的走势图, string strCategory = "优良率" + '\t' + "合格率" + '\t' + &q ...
- WCF总结笔记
------------------------windowform承载服务步骤: (1)定义契约: using System; using System.Collections.Generic; u ...
- iOS基础 - 多媒体
一.播放视频 iOS提供了叫做MPMoviePlayerController.MPMoviePlayerViewController的两个类,可以用来轻松播放视频 YouTobe就是用MPMovieP ...
- C# socket编程实践
C# socket编程实践——支持广播的简单socket服务器 在上篇博客简单理解socket写完之后我就希望写出一个websocket的服务器了,但是一路困难重重,还是从基础开始吧,先搞定C# ...
- 分享Syslinux4USB 0.3源码——改自神雕大侠作品
神雕大侠写的Syslinux4USB是我在无忧论坛里找到的工具,他是2011年写出的,他在帖子里也发布了源码,可惜那个帖子里的链接失效了,我为了这个工具的源码找了2年,终于在Google上搜到了,并且 ...
- 网站部署到Windows Azure Website上
使用CSDN Code将网站部署到Windows Azure Website上 在云计算时代,开发和部署应该是完全统一和集成的.在海外,开发者可以用github来管理他们的代码,并且直接部署到Wind ...
- 查找算法---find运算,find_first_of的使用
查找算法---find运算,find_first_of的使用 一.find运算 假设有一个int型的vector对象,名为vec,我们想知道其中是否包含某个特定值. 解决这个问题最简单的方法时使用标准 ...
- Closures in OOC
Closures in OOC 接上一篇Complexity Behind Closure,这次来专注于Rock是如何在C里实现Closure的. 这篇文章同时发布在Github上. Block as ...
- CloudFoundry虚拟机实例配置DNS
使用Bosh成功部署CloudFoundry后,在OpenStack上启了一个实例作为DNS服务器专用,配置域名mycloud.com解析到CF API接口的IP:10.68.19.134,然后使用C ...
- Haxe2.10到Haxe3,NME到OpenFL的迁移备忘
终于决定正式向Haxe3和OpenFL迁移了,这期间也遇到不少问题,这里总结记录如下: 首先是Haxe3环境 * 因为还想保留Haxe 2.10的环境,因此没有使用官网的Haxe 3安装包,而是下载了 ...