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): 24944 Accepted Submission(s): 8417

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(‘\t’), enter(‘\n’) 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!

翻译

伊格内修斯很幸运,他昨天遇到了一个火星人。但他不知道火星人使用的语言。火星人给了他一本火星历史书和一本字典当它离开时。现在伊格内修斯想把历史书翻译成英语。你能帮助他吗?
输入
这个问题只有一个测试用例,测试用例由两个部分组成,字典部分和book部分。字典部分从单行开始,包含一个字符串“开始”,这个字符串应该被忽略,然后一些行跟随,每一行包含两个字符串,第一个是英语单词,第二个是在火星语中对应的单词。带有单个字符串“END”的一行表示目录部分的结束,而该字符串应该被忽略。书的部分开始于一行包含一个字符串“开始”,这个字符串应该被忽略,然后是用火星语言写的文章。你应该用字典把这篇文章译成英语。如果你在字典里找到这个词,你应该翻译它,把生词写在你的译文里,如果你找不到字典里的词,你就不用翻译它,只要把旧的字复制到你的翻译上就行了。空格(’ ‘),标签(’ \t ‘),输入(’ \n ‘),所有的标点符号都不应该翻译。一行有一个字符串“END”表示book部分的结尾,这也是输入的末尾。所有单词都在小写字母中,每个单词最多包含10个字符,每行包含最多3000个字符。
输出
在这个问题上,你必须输出历史书的翻译。

代码:

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
int main()
{
    string a,b;
    map<string,string> mp;
    cin>>a;
    while(cin>>a&&a!="END")
    {
        cin>>b;
        mp[b]=a;
    }
    cin>>a;
    getchar();
    char ch[3005];
    while(1)
    {
        gets(ch);
        int i,len;
        if(strcmp(ch,"END")==0)
            break;
        len=strlen(ch);
        b="";
        for(i=0; iif(ch[i]<'a'||ch[i]>'z')///当ch[i]不是字母的时候输出‘b’对应的单词;
            {
                if(mp[b]!="")       ///如果‘b’有对应的单词时直接输出对应的单词
                    cout<else                ///如果‘b’没有对应的值时直接输出‘b‘;
                    cout<"";               ///初始化’b‘;
                cout<else
                b+=ch[i];///当ch[i]是字母的时候用原来的字符串加上ch【i】;
        }
        cout<return 0;
}

你可能感兴趣的:(ACM_字符类,ACM_搜索)