zoukankan      html  css  js  c++  java
  • 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:

     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 100002
    10 
    11 struct dic
    12 {
    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())!='
    ')
    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
    ");
    47         else printf("%s
    ",result->value);
    48     }
    49     //system("pause");
    50     return 0;
    51 }

    5.Reference:

  • 相关阅读:
    Tensorflow 搭建自己的神经网络(二)
    Tensorflow 搭建自己的神经网络(一)
    JSON简介
    JS 弹出框计时器
    【扫盲】史上最全的互联网专业词语汇总,小白必备,人手一套!
    推荐几个数据分析网站
    转:一位阿里人对数据模型建设的几点思考与总结
    数据模型设计心得
    数据仓库架构设计
    数据仓库建模与ETL的实践技巧(转载)
  • 原文地址:https://www.cnblogs.com/mobileliker/p/3937188.html
Copyright © 2011-2022 走看看