• What Are You Talking About


    What Are You Talking About

    Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 102400/204800K (Java/Other)
    Total Submission(s) : 20   Accepted Submission(s) : 6

    Font: Times New Roman | Verdana | Georgia

    Font Size:

    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
    题意:开始时START
    创建一本单词本
    END结束;
    START:
    翻译开始:
    END翻译结束;
    这题容易联想到STL 里的 map
    #include<map>
     
    map<类型,类型> ma;
    map<类型,类型>::iterator it; 定义一个迭代器
    it=ma.find(对象)
    因为 find() 返回迭代器;
    it->second 就返回 值
    map(key,value)
    it->second 返回value;
    #include<iostream>
    #include<string>
    #include <algorithm>
    #include<map>
    using namespace std;
    int main()
    {
        
        //a.insert(pair<string,string>("aaaa","bbb"));
    
    
        string x,y;
        while(cin>>x)
        {
            map<string,string> mapp;    
             map<string,string>::iterator it;
            if(x=="START")
            {
                while(cin>>x)
                {
                    if(x=="END")
                    {
                        break;
                    }
                    cin>>y;
                
                 mapp.insert(pair<string,string>(y,x));
                }//构建地图;//地图完成
                cin>>x;
                if(x=="START")//翻译开始+++++
                {
                    char word[3005];
                    getchar();
                    while(gets(word))
                    {
                        if(word[0]=='E'&&word[1]=='N'&&word[2]=='D')
                            break;//翻译结束
    
    
                        //翻译开始
                        int num;//
                        int numm=strlen(word); 
                        for(num=0;num<numm;)
                        {
                            
                            if((word[num]>='a'&&word[num]<='z')||(word[num]>='A'&&word[num]<='Z'))//找出单词并输出
                            {
                                string words;
                                string linshi;
                                while((word[num]>='a'&&word[num]<='z')||(word[num]>='A'&&word[num]<='Z'))
                                {
                                    linshi=word[num++];
                                    words.insert(words.length(),linshi);
                                }//得到单词;
                                it=mapp.find(words);
                                if(it!=mapp.end())
                                {
                                    
                                    cout<<it->second;
                                
                                }
                                else
                                {
                                    cout<<words;
                                
                                }
                            
                            }
                            else 
                            {
                                printf("%c",word[num++]);//词典没有就原样输出
    
                            }
                        
                        
                        }
                        printf("
    ");
                    
                    }
                }
    
    
            }
            else
            {break;}
    
        }
    
        return 0;
    }
     
  • 相关阅读:
    tomcat 无法clean 的bug
    Open Type vs Open resource
    Cannot change version of project facet Dynamic Web Module to 2.4.
    股权稀释
    Java的各种打包方式
    记忆
    【转】给女儿的信
    买房费用
    工作职场
    装修-水电改造
  • 原文地址:https://www.cnblogs.com/2013lzm/p/3263884.html
Copyright © 2020-2023  润新知