Poj 2503 / OpenJudge 2503 Babelfish
1.Link:
http://poj.org/problem?id=2503
http://bailian.openjudge.cn/practice/2503/
2.Content:
Babelfish
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32783 Accepted: 14093 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
oopslaySample Output
cat
eh
loopsHint
Huge input and output,scanf and printf are recommended.Source
3.Method:
4.Code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib> using namespace std; #define MAX_LENGTH 11
#define MAX_CONTENT 100002 struct dic
{
char key[MAX_LENGTH];
char value[MAX_LENGTH];
}a[MAX_CONTENT]; int mycmp(const void *x,const void *y)
{
return strcmp(((dic*)x)->key,((dic*)y)->key);
} int mycmp_bsearch(const void *x,const void *y)
{
return strcmp((char*)x,((dic*)y)->key);
} int main()
{
char key[MAX_LENGTH],value[MAX_LENGTH];
dic* result;
int i=;
while((value[]=getchar())!='\n')
{
scanf("%s %s",value+,key);
strcpy(a[i].key,key);
strcpy(a[i++].value,value);
getchar();
} qsort(a,i,sizeof(dic),mycmp); while(scanf("%s",key)!=EOF)
{
result=(dic*)bsearch(key,a,i,sizeof(dic),mycmp_bsearch);
if(result==NULL) printf("eh\n");
else printf("%s\n",result->value);
}
//system("pause");
return ;
}
5.Reference:
Poj 2503 / OpenJudge 2503 Babelfish的更多相关文章
- Poj 2109 / OpenJudge 2109 Power of Cryptography
1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power o ...
- Poj 1328 / OpenJudge 1328 Radar Installation
1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar I ...
- Poj 2262 / OpenJudge 2262 Goldbach's Conjecture
1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...
- Poj 2159 / OpenJudge 2159 Ancient Cipher
1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...
- Poj 1017 / OpenJudge 1017 Packets/装箱问题
1.链接地址: http://poj.org/problem?id=1017 http://bailian.openjudge.cn/practice/1017 2.题目: 总时间限制: 1000ms ...
- Poj 1001 / OpenJudge 2951 Exponentiation
1.链接地址: http://poj.org/problem?id=1001 http://bailian.openjudge.cn/practice/2951 2.题目: Exponentiatio ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- Poj 2586 / OpenJudge 2586 Y2K Accounting Bug
1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS Memory Lim ...
- Redis-cluster集群【第四篇】:redis-cluster集群配置
Redis分片: 为什么要分片:随着Redis存储的数据越来越庞大,会导致Redis的性能越来越差! 目前分片的方法: 1.客户端分片 在应用层面分片,程序里指定什么数据存放在那个Redis 优势: ...
随机推荐
- 不会内存溢出的Android Handler写法
private static class ThisHandler extends Handler { private final WeakReference<MainActivity&g ...
- android146 360 病毒查杀
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- C专家编程 总结
1 类型转换 当执行算术运算时,操作数的类型如果不同,就会发生转换,数据类型一般朝着浮点精度高.长度更长的方向转换,整数型如果转换为signed不会丢失信息,就转换为signed,否则转换为unsig ...
- easyeclipse for php 如何默认显示行号
呃... 相当简单 window->preferences->PHPeclipse web development->php 然后找到appearance选项卡 在 show lin ...
- VIM标记 mark 详解
转载:http://blog.163.com/lgh_2002/blog/static/44017526201081154512135/ 我的vim配置:http://pan.baidu.com/s/ ...
- Shlwapi.h Shlwapi.dll 动态库
Windows中有一个Shlwapi.dll文件,包含了大量的Windows字符串处理方法,这些方法,在通常的程序应用中,经常会用到,有一部分处理方法,在CRuntime中也存在,但不方便使用.有一部 ...
- iOS AR技术初体验,使用EasyAR示例程序的小白指南
QQ前两天的传递火炬,是我第一次直接接触到AR.(虽然之前听同事说过,因为他喜欢玩游戏,PS.3DS等等都玩过,这个技术最开始就是从这里出现的).所以感觉很有趣,就想自己也试着搞一下玩玩...下面是我 ...
- 故事板 — 视图切换(segue)与传值
1.传值问题:为什么不能给控件的接口赋值 如执行Segue跳转 [self performSegueWithIdentifier:GAPlayeVideo sender:gaVideo]; //在跳转 ...
- 学习css简单内容
Css的class,ID和上下文选择符 Class选择符. Class选择符用来配置某一类css规则,将其应用到网页中一个或多个区域.配置一类样式时,要将选择符配置成类名.在类名前加(.).类名必须以 ...
- Web前端学习笔记1
Day1. 1.Windows常用快捷键. 快捷键 功能 ctrl+c 复制 ctrl+v 粘贴 ctrl+x 剪切(复制和剪切后都可以粘贴) ctrl+a 全选 ctrl+s 保存 ctrl+tab ...