题目描述
We all know that FatMouse doesn't speak English. But now he has to be prepared since our nation will join WTO soon. Thanks to Turing we have computers to help him.
输入
Input consists of up to 100,005 dictionary entries, followed by a blank line, followed by a message of up to 100,005 words. Each dictionary entry is a line containing an English word, followed by a space and a FatMouse word. No FatMouse word appears more than once in the dictionary. The message is a sequence of words in the language of FatMouse, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
输出
Output is the message translated to English, one word per line. FatMouse words not in the dictionary should be translated as "eh".
样例输入
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
样例输出
cat
eh
loops
参考代码
#include<stdio.h>
#include<string.h>
struct
{
char z[15],j[15];
}
c[100010];
int fac(int n, char *a)
{
int left=0,right=n,mid;
while(left<right)
{
mid=(left+right)/2;
if(strcmp(c[mid].j,a) == 0)
return mid; else if(strcmp(c[mid].j,a) > 0)
right=mid; else
left = mid + 1;
}
return -1;
}
int main()
{
int n=0,k=1;
char a[30];
while(gets(a)&&strlen(a)!=0)
{
sscanf(a,"%s%s",c[n].z,c[n].j);
n++;
}
while(gets(a))
{
k=fac(n,a);
if(k==-1)
puts("eh"); else
puts(c[k].z);
}
return 0;
}
解析
暂无