• hdoj1075-What Are You Talking About 【map】


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

    What Are You Talking About

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


    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!

    题目大意:给你一些字符串和对应的字符串,然后给出一些话,然后根据之前的字符串来对应输出,如果没有对应,则输出原来的字符串。

    代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 #include <string>
     7 #include <map>
     8 using namespace std;
     9 
    10 #define MAX 0x7fffffff
    11 #define N 3000
    12 
    13 map<string,string> m;
    14 map<string,string>::iterator it;
    15 
    16 int main(){
    17     //freopen("D:\input.in","r",stdin);
    18     //freopen("D:\output.out","w",stdout);
    19     char s1[N],s2[N];
    20     gets(s1);
    21     while(1){
    22         scanf("%s",s1);
    23         if(s1[0]=='E'){
    24             break;
    25         }else{
    26             scanf("%s",s2);
    27             m.insert(pair<string,string>(string(s2),string(s1)));
    28         }
    29     }
    30     gets(s1);
    31     gets(s1);
    32     while(1){
    33         gets(s1);
    34         if(s1[0]=='E'){
    35             break;
    36         }else{
    37             int len=strlen(s1),step=0;
    38             for(int i=0;i<len;i++){
    39                 if(s1[i]>='a'&&s2[i]<='z'){
    40                     s2[step++]=s1[i];
    41                     continue;
    42                 }else{
    43                     s2[step]='';
    44                     it=m.find(string(s2));
    45                     if(it!=m.end()){
    46                         printf("%s",(*it).second.c_str());
    47                     }else{
    48                         printf("%s",s2);
    49                     }
    50                     step=0;
    51                     putchar(s1[i]);
    52                 }
    53             }
    54             puts("");
    55         }
    56     }
    57     return 0;
    58 }
    View Code
  • 相关阅读:
    elasticsearch + kibana 安装
    JSON Web Token
    JConsole和VisualVM远程访问JMX
    DNS域名解析
    Spring Cloud(2)主要组件应用实例
    Docker(三):Docker入门教程-CentOS Docker 安装
    Spring Cloud(1)相关概念
    Zookeeper实现哨兵机制
    大数据学习笔记之初识Hadoop
    大数据学习笔记之大数据概述
  • 原文地址:https://www.cnblogs.com/jiu0821/p/4302028.html
Copyright © 2020-2023  润新知