zoukankan      html  css  js  c++  java
  • HDUOJ---What Are You Talking About

    What Are You Talking About

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

    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
     
      map 容器的应用....map[aa]=bb;
      STL;
    代码:
     1 #pragma warning (disable:4786)
     2 #include<iostream>
     3 #include<map>
     4 #include<string>
     5 #include<cstdio>
     6 #include<cstring>
     7 #include<cstdlib>
     8 using namespace std;
     9 const int maxn =3002;
    10 char aa[maxn+1],bb[15];
    11 int main()
    12 {
    13     scanf("%*s");
    14     map<string,string>msg;
    15     while(scanf("%s",aa),strcmp(aa,"END"))
    16     {
    17       scanf("%s",bb);
    18         msg[bb]=aa;
    19     }
    20       scanf("%*s");
    21       getchar();
    22       map<string,string>::iterator it;
    23       memset(bb,'',sizeof(bb));
    24       while(cin.getline(aa,3002),strcmp(aa,"END"))
    25       {
    26           int step=0;
    27           for(int i=0;i<strlen(aa);i++)
    28           {
    29             if((aa[i]<'a'||aa[i]>'z'))
    30             {
    31              if(step)
    32              {
    33                 it=msg.find(bb);
    34                 if(it!=msg.end())
    35                 {
    36                   cout<<(*it).second;
    37                 }
    38                 else
    39                     printf("%s",bb);
    40                 step=0;
    41                 memset(bb,'',sizeof(bb));
    42              }
    43                 cout<<aa[i];
    44             }
    45             else
    46             {
    47               bb[step++]=aa[i];
    48             }
    49           }
    50           puts("");
    51       }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    Sencha Touch 框架快速入门系列
    dotTrace 使用说明
    CQRS架构中同步服务的一种实现方式
    C#中循环结构的效率问题
    面向领域驱动架构的查询实现方式
    最佳 jQuery
    DWZ&MVC的探索系列——Demo演示效果
    在Windows Azure中实现和调试一个WCF服务(上)
    现代软件工程开发体验:结对编程
    结对编程是什么?
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3386980.html
Copyright © 2011-2022 走看看