zoukankan      html  css  js  c++  java
  • HDU1075 What Are You Talking About

    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(' '), enter(' ') 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.

     

    //#include "stdafx.h"
    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<map>
    #include<vector>
    #include<stdio.h>
    using namespace std;
    bool Char(char ch)//判断是否为小写字母
    {
        if (ch >= 'a'&&ch <= 'z')
            return true;
        return false;
    }
    int main()
    {
        map<string, string> q;//map容器定义
        string str1, str2,sc;
        cin >> str1;
        while (cin >> str1)
        {
            if (str1 == "END") break;
            cin >> str2;
            q[str2] = str1;
        }
        cin >> str1;
        getline(cin, str1);
        while (getline(cin, str1))
        {
            str2 = "";//清空str2
            if (str1 == "END") break;
            for (int i = 0; i < str1.size(); i++)//
            {
                if (Char(str1[i]))//若为小写字母就存上
                    str2 += str1[i];//str2对象尾部追加小写字母
                else//不为小写字母的时候运行
                {
                    if (q[str2] != "")//若键值对照的数据不为空
                        cout << q[str2];//输出str2对应键值的映照数据
                    else//键值对照的数据不存在
                        cout << str2;//输出str2本身
                    cout << str1[i];//输出此时不为小写字母的字符
                    str2 = "";//清空str2
                }
            }
            cout << endl;
        }
        return 0;
    }
  • 相关阅读:
    HTML 语义化标签-新增标签介绍
    HTML基础知识点
    Android JSON 解析关键代码
    [USACO16DEC]Cities and States省市
    [洛谷P1835]素数密度
    [洛谷P1168]中位数
    [HNOI2008]越狱
    [HAOI2007]上升序列
    [SHOI2009]Booking 会场预约
    [洛谷P1892][codevs2597]团伙
  • 原文地址:https://www.cnblogs.com/XuYiting/p/9309875.html
Copyright © 2011-2022 走看看