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

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;
}