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. 嵌入式平台组件白盒测试gcov、lcov和genhtml 使用指导

    在嵌入式平台上使用了gtest白盒测试工具,覆盖了被测函数,但是不知道自己测试的效果如何,测试行覆盖率.函数覆盖率,分支覆盖率的数据. 便开始研究gcov这个代码覆盖率工具能否使用,来检查白盒测试的效 ...

  2. Android01-概述

    1.Android特点    开源和免费    强大的研发力量,完整的生态圈    互联网服务的支持 2.Android系统架构    应用层    应用框架层    系统运行库层    Linux内 ...

  3. C++字符串之一(字符表示)

    在C++中有两种类型可以用于表示字符,char和wchar_t. 但是字符串格式的标准却有很多种,如ASCII,UTF8,UTF16,UTF32等等.字符串的格式和char/wchar_t 的关系是什 ...

  4. git 删除远程主分支及其它操作

    1. 删除远程分支 如果不再需要某个远程分支了,比如搞定了某个特性并把它合并进了远程的 master 分支(或任何其他存放稳定代码的地方),可以用这个非常无厘头的语法来删除它:git push [远程 ...

  5. [转载]解析WINDOWS中的DLL文件---经典DLL解读

    [转载]解析WINDOWS中的DLL文件---经典DLL解读 在Windows世界中,有无数块活动的大陆,它们都有一个共同的名字——动态链接库.现在就走进这些神奇的活动大陆,找出它们隐藏已久的秘密吧! ...

  6. C#小性能知识

    字符串比较 string s = ""; 1) if(s == ""){} 2) if(s == string.Empty){} 3) if (string.I ...

  7. c++中,size_typt, size_t, ptrdiff_t 简介

    size_type 类型 从逻辑上来讲,size() 成员函数似乎应该返回整形数值,或如 2.2 节“建议”中所述的无符号整数.但事实上,size 操作返回的是 string::size_type 类 ...

  8. CentOS6.4中安装Python-Pip 以及Phyton gevent

    一.安装Phyton-pip 首先要安装 Setuptools wget --no-check-certificate https://pypi.python.org/packages/2.6/s/s ...

  9. 关于在storyboard拖按钮控件,手动设置代码不成功的问题

    首先,在 storyboard 中拖拽一个按钮控件.设置好约束条件

  10. 剑指offer第10题

    import java.util.Scanner; /* 前两种方法是看最低为是不是为1,不为1则向右移动. 第一种只能对正整数有效,对负数不行,因为负数用的是补码,最高外符号位为1,最后右移动,肯定 ...