鱼C论坛

 找回密码
 立即注册
查看: 2578|回复: 2

[技术交流] 047:Babelfish

[复制链接]
发表于 2018-2-18 21:07:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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.

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-2-18 21:16:58 | 显示全部楼层
[POJ 2503] 宝贝鱼翻译机 (Bablefish)

题目描述

你刚刚从滑铁卢(Waterloo)搬到了一个新的大城市。这里的人们都说着一种令人费解的外语方言。幸运的是,你有一本可以帮助你理解的词典。

输入

输入包含最多100,000条词典条目,接下来有一个空行,其次是最多100,000词的原始信息。
每一个词典条目包含用空格分开的两个字符串S1和S2,其中S1是译文,S2是原文。原始信息为多行,一行一个需要翻译的单词。
输入数据保证每一个单词的程长度不超过10个字符。

输出

对于每一个需要翻译的单词,输出翻译后的单词。若原始单词不存在在词典中,输出"eh"(不包含引号)。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-2-18 21:19:36 | 显示全部楼层
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>

  4. using namespace std;

  5. struct node
  6. {
  7.         char s1[20],s2[20];
  8. }a[100001];
  9. int cmp(node a,node b)
  10. {
  11.         return strcmp(a.s2,b.s2)<0;
  12. }
  13. int len;
  14. int main()
  15. {
  16.         len=0;
  17.         char str[50];
  18.         while(gets(str))
  19.         {
  20.                 if(str[0]=='\0')
  21.                         break;
  22.                 sscanf(str,"%s%s",&a[len].s1,&a[len].s2);
  23.                 len++;
  24.         }
  25.         sort(a,a+len,cmp);
  26.         while(gets(str))
  27.         {
  28.                 int l=0,r=len-1,mid,flag=1;
  29.                 while(l<=r)
  30.                 {
  31.                         mid=(l+r)>>1;
  32.                         int ans=strcmp(str,a[mid].s2);
  33.                         if(ans==0)
  34.                         {
  35.                                 printf("%s\n",a[mid].s1);
  36.                                 flag=0;
  37.                                 break;
  38.                         }
  39.                         else if(ans>0)
  40.                                 l=mid+1;
  41.                         else
  42.                                 r=mid-1;
  43.                 }
  44.                 if(flag)
  45.                         printf("eh\n");
  46.         }
  47.         return 0;
  48. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 10:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表