hdu 1075 What Are You Talking About(map)

What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)

Total Submission(s): 16042    Accepted Submission(s): 5198

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!

Hint

Huge input, scanf is recommended.

Author

Ignatius.L

Recommend

We have carefully selected several similar problems for you:  1800 1671 1298 1026 1016

直接map.

#include<cstring>
#include<cstdio>
#include<iostream>
#include<map>
#include<string>

using namespace std;

int main() {
    //freopen("test.in","r",stdin);
    string a,b;
    map<string,string>mp;
    while(1) {
        cin>>a;
        if(a=="START")continue;
        if(a=="END")break;
        cin>>b;
        mp[b]=a;
    }
    char s[1010];
    getchar();
    while(1) {
        gets(s);
        if(strcmp(s,"START")==0)continue;
        if(strcmp(s,"END")==0)break;
        int len=strlen(s);
        char p[40];
        int l=0;
        map<string,string>::iterator it;
        for(int i=0; i<len; i++) {
            if(s[i]<'a'||s[i]>'z') {
                if(l!=0) {
                    p[l]='\0';
                    if(mp[p]!="")
                         cout<<mp[p];
                    else
                        printf("%s",p);
                }
                printf("%c",s[i]);
                l=0;
            } else {
                p[l++]=s[i];
            }
        }
        cout<<endl;
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-18 13:23:07

hdu 1075 What Are You Talking About(map)的相关文章

HDU 1075 map or 字典树

What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 12773    Accepted Submission(s): 4069 Problem Description Ignatius is so lucky that he met a Martian yesterday. But

HDU 1075 What Are You Talking About (map解法+Trie解法)

HDU 1075 What Are You Talking About (map解法+Trie解法) ACM 题目地址: HDU 1075 What Are You Talking About 题意: 给出一个"翻译-原文"的对应表,然后给出句子,要把句子中的原文都翻译出来. 分析: 可以用map赤裸裸地做,但是比较花费时间,虽然这题时间给了5s,map解法是能过的. 不过Trie解法500+ms,果然Trie字典树才是正解啊. Trie入门题. 另外发现ios_base::sync_

HDU 1075 What Are You Talking About Trie题解

翻译火星语,不过火星语也是使用英文单词的,就是把一个单词对应到另外一个单词. 可以使用map, 使用二分,方法很多. 不过最快的应该都是Trie解法了. 把火星语挂在Trie树中,然后在叶子节点增加一个string容器,装英语单词. 查找的时候,找到了出现在Trie中的火星语,就返回string就可以了. #include <stdio.h> #include <string> #include <string.h> using namespace std; const

HDU 1075 What Are You Talking About(Trie的应用)

What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others) Total Submission(s): 20680    Accepted Submission(s): 6852 Problem Description Ignatius is so lucky that he met a Martian yesterday. But

hdu 1075 字典树

// hdu 1075 字典树 // // 题目大意: // // 给你一个字典,即有两个字符串,一个是英文,一个是火星文,然后 // 输入一段火星文,要你翻译成英文. // // 解题思路: // // 字典树,查字典嘛,有就输出查到的,没有原样输出.将火星文插入到 // 字典树中,然后在字典输中查找.找到了,输出对应的英文,否则,原样输 // 出. // // 感悟: // // 题目确实很简单,但是,没告诉数据范围啊,导致我一直RE,原来单词 // 可能对应很长的英文啊,找人家ac的开数组

hdu 4941 Magical Forest(STL之map应用)2014多校训练第7场

Magical Forest                                                                       Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description There is a forest can be seen as N * M grid. In this fore

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

题目链接: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 leav

hdu 1075 map

题意:给一个字典,和一句话,翻译一下 奇怪的格式 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<cstdio> 2 #include<iostream> 3

HDU 1075 What Are You Talking About(map或字典树)

What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 24624    Accepted Submission(s): 8280 Problem Description Ignatius is so lucky that he met a Martian yesterday. But