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. RouterOS首次打开网页强制跳转

    网上极少有关于RouterOS的第一次打开网页强制跳转主页的方法,大多数都方法是将浏览某个域名的IP地址跳转到自己的主页,这种方法有时会失效.还有一种方法就是当用户用80端口连接时,抓取源地址到地址列 ...

  2. WebClient 访问https

    解决SSH证书问题: webClient.getOptions().setUseInsecureSSL(true);//解决ssh证书访问https的问题

  3. java复制文件

    package com.test.tes; import java.io.File; import java.io.FileInputStream; import java.io.FileOutput ...

  4. 使用uwsgi 部署python web服务

    uwsgi, wsgi协议的一个很好的实现,源码在这里:https://github.com/unbit/uwsgi c语言编写,有兴趣可以研究下. 上DEMO: wsgi_server.py def ...

  5. discuz内置常用CSS代码分析

    CSS多IE下兼容HACK写法 所有 IE浏览器适用:.ie_all .foo { ... } IE6 专用:.ie6 .foo { ... } IE7 专用:.ie7 .foo { ... } IE ...

  6. struts2 校验数据的有效性 2种方式

    Struts2的数据校验: 数据的校验分为客户端校验和服务器端两种: 客户端校验:JS完成的校验.(为了提升用户体验.减少用户的输入错误) 服务器端校验:在后台的校验.(必须的.) 手动编码进行校验: ...

  7. 【转】mysql的cardinality异常,导致索引不可用

    转自:http://ourmysql.com/archives/1343 前段时间,一大早上,就收到报警,警告php-fpm进程的数量超过阈值.最终发现是一条sql没用到索引,导致执行数据库查询慢了, ...

  8. ios swift generator 文章推荐

    https://medium.com/swift-programming/sequence-beyond-primitive-iterations-in-swift-80bc2507d8cc /// ...

  9. Enum:Fliptile(POJ 3279)

    Fliptile 题目大意:农夫想要测牛的智商,于是他把牛带到一个黑白格子的地,专门来踩格子看他们能不能把格子踩称全白 这一题其实就是一个枚举题,只是我们只用枚举第一行就可以了,因为这一题有点像开关一 ...

  10. codeforces 519C. A and B and Team Training 解题报告

    题目链接:http://codeforces.com/contest/519/problem/C 题目意思:给出 n 个  experienced participants  和 m 个 newbie ...