zoukankan      html  css  js  c++  java
  • 2017ecjtu-summer training #2 POJ2503

     
                                                                                                                                                               Babelfish
    Time Limit: 3000MS   Memory Limit: 65536K
    Total Submissions: 44537   Accepted: 18800

    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.
    题意:翻译外文,根据输入的单词从字典里查找并输出对应的英文。
    该题做法很多,难点在于输入,本菜鸟用了二分查找

    AC代码
     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdlib.h>
     5 #include <iostream>
     6 #include <sstream>
     7 #include <algorithm>
     8 using namespace std;
     9 struct info
    10 {
    11     char e[20];
    12     char f[20];
    13 }d[100005];
    14 bool compare(const info &a,const info &b)
    15 {
    16     return strcmp(a.f,b.f)<0;
    17 }
    18 int main()
    19 {
    20     char a[50];
    21     int i,j,k=0;
    22     while(gets(a))
    23     {
    24         if(a[0]=='')
    25             break;
    26         sscanf(a,"%s%s",d[k].e,d[k].f);
    27         k++;
    28     }
    29     sort(d,d+k,compare);
    30     while(gets(a))
    31     {
    32         int left,right,mid,n=1;
    33         left=0;right=k-1;
    34         while(left<=right)
    35         {
    36             mid=(left+right)/2;
    37             if(strcmp(a,d[mid].f)==0)
    38             {
    39               printf("%s
    ",d[mid].e);
    40               n=0;
    41               break;
    42             }
    43             else if(strcmp(a,d[mid].f)<0)
    44                 right=mid-1;
    45             else
    46                 left=mid+1;
    47         }
    48         if(n)
    49             printf("eh
    ");
    50     }
    51     return 0;
    52 }


  • 相关阅读:
    Intern Day16
    粉红
    开始还房贷!
    Sonnet-十四行诗
    CSS兼容大全
    TCL电视直播软件
    《Linux权威指南》阅读笔记(2)
    《Linux权威指南》阅读笔记(1)
    Linux crontab定时执行任务 命令格式与详细例子
    linux下find查找命令用法
  • 原文地址:https://www.cnblogs.com/stranger-/p/7128035.html
Copyright © 2011-2022 走看看