Poj 2503 / OpenJudge 2503 Babelfish
来源:互联网 发布:怎么在淘宝上开店铺步骤 编辑:程序博客网 时间:2024/06/10 17:52
1.Link:
http://poj.org/problem?id=2503
http://bailian.openjudge.cn/practice/2503/
2.Content:
BabelfishTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 32783 Accepted: 14093Description
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 ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslaySample Output
catehloopsHint
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 10000210 11 struct dic12 {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:
0 0
- Poj 2503 / OpenJudge 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish(HASH)
- poj 2503 Babelfish
- POJ 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish 【hash】
- poj 2503 Babelfish【trie】
- POJ 2503 Babelfish
- poj-2503 Babelfish
- poj-2503 Babelfish
- poj 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish
- POJ 2503 Babelfish (Hash)
- POJ 2503 Babelfish
- Poj 2299 Ultra-QuickSort
- Poj 3006 Dirichlet's Theorem on Arithmetic Progressions
- Poj 3094 Quicksum
- 模板:cin.getline用法
- Poj 2388 Who's in the Middle
- Poj 2503 / OpenJudge 2503 Babelfish
- Poj 2965 The Pilots Brothers' refrigerator
- Poj 1328 / OpenJudge 1328 Radar Installation
- 查看linux系统版本命令
- Poj 2109 / OpenJudge 2109 Power of Cryptography
- Poj 2586 / OpenJudge 2586 Y2K Accounting Bug
- OpenJudge 2721 忽略大小写比较字符串大小
- 怎样在github上协同开发
- android+eclipse+phonegap1.7(cordova)配置项目(转)