zoukankan      html  css  js  c++  java
  • HDU——T 1075 What Are You Talking About

    http://acm.hdu.edu.cn/showproblem.php?pid=1075

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
    Total Submission(s): 24477    Accepted Submission(s): 8237


    Problem Description
    Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book into English. Can you help him?
     
    Input
    The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian's language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate it and write the new word into your translation, if you can't find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(' '), tab(' '), enter(' ') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
     
    Output
    In this problem, you have to output the translation of the history book.
     
    Sample Input
    START from fiwo hello difh mars riwosf earth fnnvk like fiiwj END START difh, i'm fiwo riwosf. i fiiwj fnnvk! END
     
    Sample Output
    hello, i'm from mars. i like earth!
    Hint
    Huge input, scanf is recommended.
     
    Author
    Ignatius.L
     
    Recommend
    We have carefully selected several similar problems for you:  1800 1671 1247 1298 1026 
     
     
    题目处理很恶心、、
     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <string>
     5 #include <cctype>
     6 #include <cstdio>
     7 #include <map>
     8 
     9 using namespace std;
    10 
    11 map<string,string>mmp;
    12 char s[3333];
    13 string a,b;
    14 
    15 int main()
    16 {
    17     cin>>a;
    18     for(;cin>>a&&a!="END";)
    19         cin>>b,mmp[b]=a;
    20     cin>>a;
    21     getchar();
    22     for(int len;gets(s)&&strcmp(s,"END");)
    23     {
    24         len=strlen(s); a="";
    25         for(int i=0;i<len;i++)
    26             if(islower(s[i])) a+=s[i];
    27             else
    28             {
    29                 if(mmp.find(a)!=mmp.end())
    30                     cout<<mmp[a];
    31                 else cout<<a;
    32                 a=""; cout<<s[i];
    33             }
    34         cout<<endl;
    35     }
    36     return 0;
    37 }
    MAP——AC
     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <string>
     5 #include <cctype>
     6 #include <cstdio>
     7 
     8 using namespace std;
     9 
    10 string a,b,ans;
    11 char s[3333];
    12 struct Trie
    13 {
    14     int next[27];
    15     string ans;
    16 }tr[1000001];
    17 int tot;
    18 
    19 inline void Trie_build()
    20 {
    21     int now=0,len=b.length();
    22     for(int i=0;i<len;i++)
    23     {
    24         int x=b[i]-'a';
    25         if(tr[now].next[x])
    26             now=tr[now].next[x];
    27         else tr[now].next[x]=++tot,now=tot;
    28     }
    29     tr[now].ans+=a;
    30 }
    31 inline bool Trie_find()
    32 {
    33     int now=0,p=0;
    34     int len=a.length();
    35     for(;p<len;p++)
    36         if(tr[now].next[a[p]-'a'])
    37             now=tr[now].next[a[p]-'a'];
    38         else return 0;
    39     ans=tr[now].ans;
    40     if(!ans.length()) return 0;
    41     return 1;
    42 }
    43 
    44 int main()
    45 {
    46     cin>>a;
    47     for(;cin>>a&&a!="END";)
    48         cin>>b,Trie_build();
    49     cin>>a;
    50     getchar();
    51     for(int len;gets(s)&&strcmp(s,"END");)
    52     {
    53         len=strlen(s); a="";
    54         for(int i=0;i<len;i++)
    55             if(islower(s[i])) a+=s[i];
    56             else
    57             {
    58                 if(Trie_find()) cout<<ans;
    59                 else cout<<a; ans="";a="";
    60                 cout<<s[i];
    61             }
    62         memset(s,0,sizeof(s));
    63         cout<<endl;
    64     }
    65     return 0;
    66 }
    Trie树——AC
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    【新梦想Java开发公开课】
    接口自动化框架httprunner(三)--断言
    接口自动化框架httprunner(二)--变量空间(context)作用域
    接口自动化框架httprunner(一)--安装及简单使用
    python+locust性能测试(四)之分布式运行
    安装Resharper 10.0.X 出现 The CrossAppDomainPointer is NULL 错误解决方案之一
    给DNN装SkinTuner扩展时出现Could not load file or assembly 'System.Data.SQLite
    STA和MTA线程模式的区别
    jQuery插件,迅速的实现拖拽功能
    query插件(三):Colorbox–内容播放插件
  • 原文地址:https://www.cnblogs.com/Shy-key/p/7398778.html
Copyright © 2011-2022 走看看