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
  • 相关阅读:
    webLogic的安装与配置总结
    hibernate 中save()、update()、saveOrUpdate()的区别?
    struts2+spring+hibernate+oracle整合,实现增删改查操作。(一)
    配置struts时web.xml中<url-pattern>*.action</url-pattern>
    java中,返回1000-10000中 能被3整除,且个位数是6的个数
    kubernetes部署Fluentd+Elasticsearch+kibana 日志收集系统
    用Docker搭建WordPress
    51建设Android版一些技术整理
    微信内置浏览器隐藏功能左上角功能选项
    vs2013修改默认的开发环境
  • 原文地址:https://www.cnblogs.com/HQHQ/p/5367963.html
Copyright © 2011-2022 走看看