[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 ...
随机推荐
- 轻量级IOC框架:Ninject
Ninject 学习杂记 - liucy 时间2014-03-08 00:26:00 博客园-所有随笔区原文 http://www.cnblogs.com/liucy1898/p/3587455.h ...
- printf code
printf背后的故事 2014-01-14 21:54 by Florian, 41 阅读, 0 评论, 收藏, 编辑 printf背后的故事 说起编程语言,C语言大家再熟悉不过.说起最简单的代码, ...
- 图解 ENGLISH
人在江湖,总得会几门手艺,英语必不可缺,下面几张图诠释了什么叫强大:
- 苹果推送通知服务Push Notification探究总结(序)
刚才发了两篇几个月前写的文档,觉得太敷衍了,想了想,还是来一发实在的. 再者,刚好上周研究了苹果的推送通知服务Push Notification,还是很有心得的,赶紧趁热打铁,记录一下,望与大家谈论下 ...
- [译]反-反汇编 & 混淆 #1: 苹果没有遵循自己制定的Mach-O规范?
原文地址:http://reverse.put.as/2012/02/02/anti-disassembly-obfuscation-1-apple-doesnt-follow-their-own-m ...
- c语言,字符串原地翻转
实现字符串的原地翻转: #include<stdlib.h> #include<stdio.h> #include<assert.h> #define SWAP(a ...
- HTTP header 介绍
HTTP(Hyper Text Transfer Protocol)是超文本传输协议的缩写,它用于传送www方式的数据.HTTP协议采用了请求/响应模型.客服端向服务器发送一个请求,请求头包含请求的方 ...
- Lucene.net入门学习系列(1)
Lucene.net入门学习系列(1) Lucene.net入门学习系列(1)-分词 Lucene.net入门学习系列(2)-创建索引 Lucene.net入门学习系列(3)-全文检索 这几天在公 ...
- Ping其他电脑ping不通的解决方法
要想Ping通其他电脑,首先要看被PING的电脑,是否允许PING. 一.在被PING电脑操作系统为XP下分为:1.被PING 电脑关闭了防火墙,就完全可以PING通:2.被PING 电脑开了防火墙, ...
- Winform程序
故事的开端是这样的,小白是一个程序员,他确实也是一个小白,目前还在程序员发展的道路上,兢兢业业的小心求学. 有一天,小白接到一个任务,完成一个Winform程序,附加一个功能就是可以读IC卡. 小白终 ...