zoukankan      html  css  js  c++  java
  • http://begin.lydsy.com/JudgeOnline/problem.php?id=2770(PKU2503 Babelfish)

    2770: PKU2503 Babelfish

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 2  Solved: 2
    [Submit][Status][Web Board]

    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

     

    Source

     题解:
      这个看一眼就知道是trie树,随便乱搞搞就可以了。。。。。。
     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 //#include<string>
     5 #define maxn 10000
     6 using namespace std;
     7 int sum[350000];
     8 int son[350000][26];
     9 char s1[100005][12],s2[100005][12];
    10 char s[100005];
    11 int tot,i,j;
    12 void insert(char *s,int num)
    13 {
    14     int p=0;
    15     for (int i=0; s[i]; p=son[p][s[i]-'a'],i++)
    16         if (!son[p][s[i]-'a']) son[p][s[i]-'a']=++tot;
    17     sum[p]=num;
    18 }
    19 int answer(char *s)
    20 {
    21     int p=0;
    22     for (int i=0; s[i]; p=son[p][s[i]-'a'],i++)
    23             if (!son[p][s[i]-'a'] ) return 0;
    24     return sum[p];
    25 } 
    26 int main()
    27 {
    28     int i=1;
    29     while (true) 
    30     {
    31         gets(s);
    32         if (s[0]=='') break;
    33         sscanf(s,"%s %s",s1[i],s2[i]);
    34         insert(s2[i],i);
    35         i++;
    36     }
    37     while (scanf("%s",s)!=-1)
    38     {
    39         i=answer(s);
    40         if (i==0) cout<<"eh"<<endl; else  cout<<s1[i]<<endl;
    41     }
    42 }
    View Code
  • 相关阅读:
    Java编程之委托代理回调、内部类以及匿名内部类回调(闭包回调)
    JavaEE开发之记事本完整案例(SpringBoot + iOS端)
    JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
    JavaEE开发之SpringBoot工程的创建、运行与配置
    JavaEE开发之SpringMVC中的自定义消息转换器与文件上传
    Scala.js v0.1 发布,在浏览器直接运行 Scala
    如何编写 Cloud9 JavaScript IDE 的功能扩展
    在 Cloud 9 中搭建和运行 Go
    MicroPHP 2.2.0 发布
    StrongSwan 5.1.1 发布,Linux 的 IPsec 项目
  • 原文地址:https://www.cnblogs.com/HQHQ/p/5367963.html
Copyright © 2011-2022 走看看