HDU 1075 What Are You Talking About (strings)

What Are You Talking About

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

Total Submission(s): 15966    Accepted Submission(s): 5177

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.

解析:将词典存在map中,然后对于history中的每个词都查找是否能在词典中找到,若能找到,则替换之;若没有,则直接输出。

AC代码:

#include <bits/stdc++.h>
using namespace std;

map<string, string> m;

int main(){
    #ifdef sxk
        freopen("in.txt", "r", stdin);
    #endif // sxk

    string s, ss;
    cin>>s;
    while(cin>>s){
        if(s == "END") break;
        cin>>ss;
        m[ss] = s;
    }
    cin>>s;
    getchar();
    ss = "";
    while(getline(cin, s)){
        if(s[0] == 'E' && s[1] == 'N' && s[2] == 'D') break;
        int n = s.size();
        for(int i=0; i<n; ){
            while(i < n && isalpha(s[i]) && s[i] != ' ') ss += s[i ++];
            if(ss == ""){ cout<<s[i ++]; continue; }
            if(m.count(ss)) cout<<m[ss];
            else cout<<ss;
            ss = "";
        }
        puts("");
    }
    return 0;
}

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

时间: 2024-08-09 08:13:15

HDU 1075 What Are You Talking About (strings)的相关文章

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): 16042    Accepted Submission(s): 5198 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 1507 Uncle Tom&#39;s Inherited Land*(二分)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1853    Accepted Submission(s): 769 Special Judge Problem Description Your old uncle Tom inherited a piece of land fr

HDU 5024 Wang Xifeng&#39;s Little Plot (搜索)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 157    Accepted Submission(s): 105 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7    Accepted Submission(s): 4 Problem Description Hanamichi is taking part in

HDU 4001 To Miss Our Children Time (动态规划)

To Miss Our Children Time Problem Description Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy

POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;s Wild Numbers(数学)

题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Description A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and

HDU - 4971 A simple brute force problem. (DP)

Problem Description There's a company with several projects to be done. Finish a project will get you profits. However, there are some technical problems for some specific projects. To solve the problem, the manager will train his employee which may

HDU 2491 Priest John&#39;s Busiest Day(贪心)

题目链接 题意: n场婚礼 给定每场婚礼的开始和结束时间,要求每场婚礼至少举行一半以上(不包括一半) 如果可行输出YES,否则输出NO 思路: 算出每场婚礼的至少要举行的时间t, 最早的结束时间mid 以最早结束时间mid为第一变量,开始时间s为第二变量从小到大排序 用cnt记录举办完每场婚礼的结束时间 分三种情况: ①加参前当婚礼的时间够不一半 ②果加参婚礼时婚礼已开始,结束时间就加上婚礼一半的时光 ③婚礼没开始,结束时间就是婚礼的最早结束时间mid 代码如下: #include<cstdio