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. 多通道(Multichannel)单通道(singlechannel)图像概念梳理

    在做机器视觉时,常常要将一个多通道图像分离成几个单通道图像或者将几个单通道图像合成一个多通道图像,以方便图像处理,但是.写这篇博客,是为加深对这两个概念的理解,下面会给出部分OpenCV对单通道与多通 ...

  2. linux下vi命令大全[转]

    进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后 ...

  3. Android实用代码模块集锦

    1. 精确获取屏幕尺寸(例如:3.5.4.0.5.0寸屏幕) 1 2 3 4 5 6 public static double getScreenPhysicalSize(Activity ctx)  ...

  4. windows下nodejs常见错误

    1.express-session express-session deprecated undefined resave option; provide resave option auth_s e ...

  5. Python自动化之sqlalchemy(修改和查询)

    修改 my_user = Session.query(User).filter_by(name="alex").first() my_user.name = "Alex ...

  6. COGS 2434 暗之链锁 题解

    [题意] 给出一个有n个点的无向图,其中有n-1条主要边且这些主要边构成一棵树,此外还有m条其他边,求斩断原图的一条主要边和一条其他边使得图不连通的方案数. 注意,即使只斩断主要边就可以使得原图不连通 ...

  7. 关于jquery on方法进行事件绑定触发次数指数叠加的问题

    发生环境: $modal.on('click', '#search',function(e){}); 上面代码的语法是这样的: .on( events [, selector ] [, data ], ...

  8. ERROR Cannot determine the location of the VS Common Tools Folder

    参考:ERROR Cannot determine the location of the VS Common Tools Folder   http://blog.csdn.net/m3728975 ...

  9. C#错误之 System.Threading.ThreadAbortException:正在中止线程

    参考:http://www.cnblogs.com/chendaoyin/archive/2013/06/27/3159211.html 1.开启一个子线程 //开启一个子线程,子线程调用方法 Met ...

  10. 【leetcode】Wildcard Matching(hard) ★ 大神太牛了

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...