首页 > 其他 > 详细

HDU 1075 What Are You Talking About(map运用)

时间:2014-09-04 22:24:00      阅读:410      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075


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!


PS:

FUCKFUCKFUCK,PE一晚上bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣

代码如下:

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <map>
using namespace std;
map<string, string>m;
int main()
{
    string s, ss;
    cin >> s;
    while(cin >> s)
    {
        if(s == "END")
            break;
        cin >> ss;
        m[ss] = s;
    }
    cin >> s;
    char tt[3017];
    getchar();
    while(gets(tt))
    {
        if(!strcmp(tt,"END"))
            break;
        ss="";
        int len = strlen(tt);
        for(int i = 0; i < len; i++)
        {
            if(!(tt[i]>='a'&&tt[i]<='z'))
            {
                if(m[ss]=="")
                    cout<<ss;
                else
                    cout<<m[ss];
                ss = "";
                cout<<tt[i];
            }
            else
                ss+=tt[i];
        }
        cout<<endl;
    }
    return 0;
}


HDU 1075 What Are You Talking About(map运用)

原文:http://blog.csdn.net/u012860063/article/details/39059387

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!