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. CSS自学笔记(11):CSS3背景和边框

    CSS3 背景 在CSS3中新增了多个关于背景的属性,可以让我们对背景有了更多更好的操作,减少用第三方工具对背景图片进行修改美化. CSS3中主要是通过定义backgrounp中的各个属性来控制背景( ...

  2. lua学习笔记(1)-基本语法

    ==============变量类型nilnumber(实数)    1 2 3.14 7.65e8string            "hello world" "\n ...

  3. Delphi 实现无窗口移动(发WM_NCHITTEST消息计算,然后再发WM_SYSCOMMAND消息,带参数SC_DRAGMOVE)

    procedure imgListMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) ...

  4. python魔术方法

    在类中有一些特殊的方法具有特殊的意义,比如__init__和__del__方法,它们的重要性我们已经学习过了. 一般说来,特殊的方法都被用来模仿某个行为.例如,如果你想要为你的类使用x[key]这样的 ...

  5. 微信的分享功能(针对web手机站页面进行的分享功能)

    把这段js粘贴进,设置可以分享的页面,当微信打开,即可微信进行分享各个圈 $(function(){ var lujing=$("#logimg").attr("src& ...

  6. HipHop算法:利用微博互动关系挖掘社交圈

    /* 版权声明:可以任意转载,转载时请务必标明文章原始出处和作者信息 .*/                  CopyMiddle: 张俊林 TimeStamp:2012年3 月 在微博环境下,如何 ...

  7. linux下创建可引导的U盘系统,使用dd命令进行Linux的ghost

    1,通过iso创建可引导的U盘系统. 1.0,格式化U盘为FAT32格式 linux下能够使用命令: mkfs.vfat U盘的设备路径 比如: mkfs.vfat /dev/sdb 当中U盘的路径能 ...

  8. 9大理由告诉你为什么应该学习HTML跟CSS

    你是不是听过太多人告诉你:「人人都应该要会 coding!」都快要不耐烦了对吧? 究竟为什么身为一个行销专业者.作家.金融巨擘--,整个世界还要你学会 coding? 事实上仅仅要对 HTML.CSS ...

  9. 错误:C:\Windows\System32\ssleay32.dll: Can't load IA 32-bit .dll on a AMD 64-bit

    错误:C:\Windows\System32\ssleay32.dll: Can't load IA 32-bit .dll on a AMD 64-bit 错误的原因是:jdk不是64位的,而是32 ...

  10. uva 103 Stacking Boxes(DAG)

    题目连接:103 - Stacking Boxes 题目大意:有n个w维立体, 输出立体互相嵌套的层数的最大值, 并输出嵌套方式, 可嵌套的要求是外层立体的w条边可以分别对应大于内层立体. 解题思路: ...