Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 28581   Accepted: 12326

题目链接:http://poj.org/problem?id=2503

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.

Source

代码:

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
struct vode
{
char eng[];
char dic[];
};
struct vode g[];
int strr ( const void *a , const void *b )
{
return strcmp( ((vode *)a)->dic , ((vode *)b)->dic );
}
int binsearch(int s,int t,char dic[])
{
int low=s,high=t,mid;
if(s<=t)
{
mid=low+(high-low)/;
if(strcmp(g[mid].dic,dic)==)return mid;
if(strcmp(g[mid].dic,dic)>)
return binsearch(low,mid-,dic);
else
return binsearch(mid+,high,dic);
}
return -;
}
int main()
{
char dic[];
int i;
//下面的for循环控制字典的输入和结束,是本题的重点所在******
for(i=;dic[]!='\0';i++)
{
gets(dic);
sscanf(dic,"%s%s",g[i].eng,g[i].dic);
//printf("dic[%d]:%s g[%d].eng:%s g[%d].dic:%s\n\n",i,dic,i,g[i].eng,i,g[i].dic);//验证输出
}
qsort(g,i,sizeof(g[]),strr);
while(scanf("%s",dic)!=EOF)
{
int flag=binsearch(,i-,dic);
if(flag>=)cout<<g[flag].eng<<endl;
else cout<<"eh"<<endl;
}
return ;
}

Babelfish(二分查找,字符串的处理略有难度,用sscanf输入)的更多相关文章

  1. 数据结构和算法:Python实现二分查找(Binary_search)

    在一个列表当中我们可以进行线性查找也可以进行二分查找,即通过不同的方法找到我们想要的数字,线性查找即按照数字从列表里一个一个从左向右查找,找到之后程序停下.而二分查找的效率往往会比线性查找更高. 一. ...

  2. C#LeetCode刷题-二分查找​​​​​​​

    二分查找篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30 ...

  3. 二分查找-python

    约12年年底的时候,接触了python不到半年的样子,入门是直接实现GUI测试case的.今天面试地平线机器人,发现忘得差不多了- -. 当时的问题是这样的 写一个二分查找是实现,我好像不记得二分查找 ...

  4. 工作的准备:atoi,itoa,strcpy,memcpy,strcmp,二分查找,strcat

    对常见的几个函数,周末没事写写,绝对是笔试面试中非频繁,前面n届学长无数次强调了,大家就别怀疑了.从今天开始,每天10道题. int atoi(const char* str) { if(str==N ...

  5. Java数据结构和算法总结-数组、二分查找

    前言:在平时开发中数组几乎是最基本也是最常用的数据类型,相比链表.二叉树等又简单很多,所以在学习数据和算法时用数组来作为一个起点再合适不过了.本篇博文的所有代码已上传 github ,对应工程的 ar ...

  6. 《java入门第一季》之Arrays类前传(排序案例以二分查找注意的问题)

    根据排序算法,可以解决一些小案例.举例如下: /* * 把字符串中的字符进行排序. * 举例:"dacgebf" * 结果:"abcdefg" * * 分析: ...

  7. Long Long Ago 二分查找

    L: Long Long Ago 时间限制: 1 s      内存限制: 128 MB 提交 我的状态 题目描述 今天SHIELD捕获到一段从敌方基地发出的信息里面包含一串被经过某种算法加密过的的序 ...

  8. 使用二分查找判断某个数在某个区间中--如何判断某个IP地址所属的地区

    一,问题描述 给定100万个区间对,假设这些区间对是互不重叠的,如何判断某个数属于哪个区间? 首先需要对区间的特性进行分析:区间是不是有序的?有序是指:后一个区间的起始位置要大于前一个区间的终点位置. ...

  9. python bisect 排序模块 二分查找与 bisect 模块

    python 3.6.5 import bisect bisect_list=dir(bisect)print(bisect_list)bisect_list = ['__builtins__', ' ...

随机推荐

  1. python traceback 变量值

    import sys import traceback import cgitb def handleException(excType, excValue, trace): print 'error ...

  2. ubuntu安装skype

    1.添加源 sudo add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -sc) partner&quo ...

  3. HTML中属性ID和属性NAME有何区别?

    今天出美工面试题的时候,David让我加上一道题:HTML中id和name的区别.一听对呀,HTML中id和name有什么区别,只是平时在用,倒没怎么想过,只是那么用了罢了,呵呵,其实在做网页的时候有 ...

  4. ubuntu14.04 163sources.list

    deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.163 ...

  5. 十一天 python操作rabbitmq、redis

    1.启动rabbimq.mysql 在""运行""里输入services.msc,找到rabbimq.mysql启动即可 2.启动redis 管理员进入cmd, ...

  6. 解读Unity中的CG编写Shader系列十 (光滑的镜面反射(冯氏着色))

    前文完成了最基本的镜面反射着色器,单平行光源下的逐顶点着色(per-vertex lighting),又称为古罗着色(Gouraud shading).这篇文章作为后续讨论更光滑的镜面反射方式,逐像素 ...

  7. linux的提示信息--/etc/motd和/etc/issue

    /etc/motd 即 message of the day 每次用户登录时,这个文件的内容都会显示在用户的终端上.如果shell支持中文,还可以使用中文,这样看起来更加舒服. 成功登录后,自动输出. ...

  8. ACM/ICPC 之 Floyd范例两道(POJ2570-POJ2263)

    两道以Floyd算法为解法的范例,第二题如果数据量较大,须采用其他解法 POJ2570-Fiber Network //经典的传递闭包问题,由于只有26个公司可以采用二进制存储 //Time:141M ...

  9. ffmpeg-20160701-git-bin.7z

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  10. nyoj221_Tree_subsequent_traversal

    Tree 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 Little Valentine liked playing with binary trees very ...