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

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:

上一篇:安装Windows Azure Powershell


下一篇:运行startup.bat的启动过程