Babelfish
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 37238   Accepted: 15879

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
题解:此处用到了sscanf的用法,很巧妙;
代码:
 #include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int MAXN=;
struct Node{
char en[],ei[];//无语开小了。。。
};
Node dt[MAXN];
int cmp(Node a,Node b){
return strcmp(a.ei,b.ei)<;
}
int erfen(char *x,int l,int r){
while(l<=r){
int mid=(l+r)>>;
if(!strcmp(dt[mid].ei,x))return mid;
if(strcmp(dt[mid].ei,x)>)r=mid-;
else l=mid+;
}
return -;
}
int main(){
int dm=;
char str[];
Node a;
while(gets(str)){
if(str[]=='\0')break;
sscanf(str,"%s%s",a.en,a.ei);//这里很巧妙。。。
dt[dm++]=a;
}
sort(dt,dt+dm,cmp);
while(~scanf("%s",str)){
int t=erfen(str,,dm-);
if(t==-)puts("eh");
else printf("%s\n",dt[t].en);
}
return ;
}

Babelfish(二分)的更多相关文章

  1. Babelfish(二分查找,字符串的处理略有难度,用sscanf输入)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28581   Accepted: 12326 题目链接: ...

  2. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  3. poj 2503 Babelfish(字典树或map或哈希或排序二分)

    输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...

  4. POJ 2503.Babelfish-sscanf()函数+strcmp()函数+二分

    Babelfish   Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 44545   Accepted: 18803 Des ...

  5. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  6. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  7. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  8. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  9. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

随机推荐

  1. python语言

    python语言 因为我比较熟悉python语言,所以月刊中python语言的项目居多,个人能力有限,其他语言涉及甚少,欢迎各路人士加入,丰富月刊的内容. 当然,如果您有更好的建议或者意见,欢迎发邮件 ...

  2. python---连接MySQL第一页

    前言:python如果想要连接到MySQL要安装上相关的驱动才下:好在驱动程序在mysql的官网可以下载的到. 以下是我自己保存的一个conetos7版本 http://yunpan.cn/cLACS ...

  3. Oracle EBS-SQL (WIP-14):检查车间需求与BOM差异对照.sql

    select a.*, b.BOM定额, a.WIP定额 - b.BOM定额     差异 from (select WE.WIP_ENTITY_NAME                        ...

  4. 使用Flex图表组件

    原文 http://blog.csdn.net/mylxiaoyi/article/details/1618470 使用Flex图表组件 以图表或是图的方式显示数据的能力可以使得Flex程序用户的数据 ...

  5. POJ——放苹果

    4:放苹果 查看 提交 统计 提问 总时间限制:  1000ms  内存限制:  65536kB 描述 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示) ...

  6. zip命令

    常用示例: (1)zip -r myfile.zip ./*    ----将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件, -r表示递归压缩子目录下所有文件. (2)unzip - ...

  7. linux中ctrl+z、ctrl+d和ctrl+c的区别

    ctrl+c和ctrl+z都是中断命令,但是他们的作用却不一样.ctrl+c是强制中断程序的执行,而ctrl+z的是将任务中断,但是此任务并没有结束,他仍然在进程中他只是维持挂起的状态,用户可以使用f ...

  8. Copy from chromium-dev!

    https://app.yinxiang.com/pub/gguangle0/chromium-dev 做了一些搬运工的活..............

  9. Swfit中视图跳转

    .跳转到任一UIViewController var sb = UIStoryboard(name: "Main", bundle:nil) var vc = sb.instant ...

  10. C结构体中位域

    C结构体中位域的一点小知识,最近在看资料时遇到结构体中的一种特殊操作——位域,在下面的程序中我将根据自己的理解进行简单介绍.程序只是为了了解位域的一些性质,运行时有些编译器可能会报错. 程序代码如下( ...