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 优势: ...
随机推荐
- spring mvc --自己定义converse
在MVC中我们能够非常轻松的依据项目需求进行必要的信息转换,如设置默认的日期格式,自己定义String类型的格式等等... 配置中我们须要自己定义converseService: <bean i ...
- Android通过http协议POST传输方式
Android通过http协议POST传输方式如下: 方式一:HttpPost(import org.apache.http.client.methods.HttpPost) 代码如下: privat ...
- android短信发送器源代码
Activity类: import java.util.List;import android.app.Activity;import android.app.PendingIntent;import ...
- Android 滑动效果高级篇(八)—— 自定义控件
自定义控件,较常用View.ViewGroup.Scroller三个类,其继承关系如下: 本示例自定义控件,实现一个Gallery效果,并添加了一个显示View个数和位置的bar条,效果图: 自定义控 ...
- Metadata Lock原理1
https://www.percona.com/blog/2013/02/01/implications-of-metadata-locking-changes-in-mysql-5-5/ impli ...
- android:layout_weight总有你不知道的用法.
都知道weight是权重的意思. 在布局中起到非常重要的作用. 但是这玩意不能嵌套使用, 而且只能使用在LinearLayout中. 下面说说它的几种用法(以下例子全为横排 注意android:lay ...
- Oracle_集合
游标遍历select语句 set serveroutput on; declare type sp_test1_cursor is ref cursor; test1_cursor sp_test1_ ...
- Linux 学习笔记 文件权限
* Linux系统会为各种各样的功能创建不同的用户账户,而这些账户并不是真的用户.这些账户称作系统账户,是系统上运行的各种服务进程访问资源用的特殊账户. 所有运行在后台的服务都需要用一个系统用户账户登 ...
- 最新搭建GIT服务器仓库
新开了一个项目,现在需要将代码放在公司GIT服务器上面.所以这里需要了一些问题..记录一下.因为原来公司这边的服务器的git用户都是创建好的.这里没有创建.需要的可以看看:http://www.cnb ...
- JQuery EasyUI 之 DataGrid
1.动态创建datagrid 在页面上添加一个div或table标签,然后用jquery获取这个标签,并初始化一个datagrid.代码如下: (1)页面上添加div标签 <div id=&qu ...