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
oopslay

Sample Output

cat
eh
loops

Hint

Huge input and output,scanf and printf are recommended.

Source

Waterloo local 2001.09.22

3.Method:

4.Code:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5
 6 using namespace std;
 7
 8 #define MAX_LENGTH 11
 9 #define MAX_CONTENT 100002
10
11 struct dic
12 {
13    char key[MAX_LENGTH];
14    char value[MAX_LENGTH];
15 }a[MAX_CONTENT];
16
17 int mycmp(const void *x,const void *y)
18 {
19     return strcmp(((dic*)x)->key,((dic*)y)->key);
20 }
21
22 int mycmp_bsearch(const void *x,const void *y)
23 {
24     return strcmp((char*)x,((dic*)y)->key);
25 }
26
27
28 int main()
29 {
30     char key[MAX_LENGTH],value[MAX_LENGTH];
31     dic* result;
32     int i=0;
33     while((value[0]=getchar())!=‘\n‘)
34     {
35         scanf("%s %s",value+1,key);
36         strcpy(a[i].key,key);
37         strcpy(a[i++].value,value);
38         getchar();
39     }
40
41     qsort(a,i,sizeof(dic),mycmp);
42
43     while(scanf("%s",key)!=EOF)
44     {
45         result=(dic*)bsearch(key,a,i,sizeof(dic),mycmp_bsearch);
46         if(result==NULL) printf("eh\n");
47         else printf("%s\n",result->value);
48     }
49     //system("pause");
50     return 0;
51 }

5.Reference:

时间: 2024-08-12 17:18:41

Poj 2503 / OpenJudge 2503 Babelfish的相关文章

Poj 2262 / OpenJudge 2262 Goldbach&#39;s Conjecture

1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37791   Accepted: 14536 Description In 1742, Christian Goldbach, a German a

Poj 2109 / OpenJudge 2109 Power of Cryptography

1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18872   Accepted: 9520 Description Current work in cryptography involves (

Poj 2159 / OpenJudge 2159 Ancient Cipher

1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Cipher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28064   Accepted: 9195 Description Ancient Roman empire had a strong government system

Poj 1328 / OpenJudge 1328 Radar Installation

1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 52833   Accepted: 11891 Description Assume the coasting is an infinite straig

Poj 2586 / OpenJudge 2586 Y2K Accounting Bug

1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10520   Accepted: 5257 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some

Redis-cluster集群【第四篇】:redis-cluster集群配置

Redis分片: 为什么要分片:随着Redis存储的数据越来越庞大,会导致Redis的性能越来越差! 目前分片的方法: 1.客户端分片 在应用层面分片,程序里指定什么数据存放在那个Redis  优势:比较灵活    缺点:加个节点扩容就很费劲 2.代理Proxy分片  第三方的Twemproxy  使用代理的缺点,你代理什么性能,那么你整个Redis的性能就是什么样的! 3.redis cluster 4.codis (豌豆荚)开源 Redis cluster: 这里摘录:http://redi

POJ 2503 Babelfish (Trie树 或 map)

Babelfish Time Limit: 3000MS        Memory Limit: 65536K Total Submissions: 34278        Accepted: 14706 Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately

poj 2503:Babelfish(字典树,经典题,字典翻译)

Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 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

poj 2503 Babelfish (map,trie 树)

链接:poj 2503 题意:输入 语言A及翻译为语言B的词典,之后再输入语言B的单词,判断是否能从词典中找到, 若能找到,将其翻译为语言A,否则输出"eh". 思路:这题肯定得先将词典对应语言存起来,但是如果直接暴力找输入的单词是否出现过,必然会TLE 因为单词都是一对一的关系,可以用map实现 当然,trie树是用空间换时间,对于字符串的查找,在时间上有着相当的优势,因此也可以用trie树 注:sscanf函数,从一个字符串中读进与指定格式相符的数据. map实现:938MS #i