首页 > 其他分享 >hdu: What Are You Talking About(map应用)

hdu: What Are You Talking About(map应用)

时间:2022-12-27 19:34:11浏览次数:40  
标签:map About word string dictionary s1 hdu should END

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.


输入样例

START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END

输出样例

hello, i'm from mars.
i like earth!
题目关键在s2的表示;
附ac代码
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
bool pd(char c)
{
    if (c >= 'a' && c <= 'z')
        return 1;
    else
        if (c >= 'A' && c <= 'Z') return 1;
        else return 0;

}
int main()
{
    string s1, s2;
    map<string, string> m;
    while (cin >> s1)
    {
        while (cin >> s1)
        {
            if (s1 == "END") break;
            cin >> s2;
            m[s2] = s1;
        }
        cin >> s1;
        s2="";
        while (getline(cin, s1))
        {
            if (s1 == "END") break;
            else
                for (int i = 0; i < s1.size(); ++i)
                {
                    if (!pd(s1[i]))
                    {
                        if (m.count(s2)) cout << m[s2];
                        else cout << s2;
                        cout << s1[i];
                        s2 = "";
                    }
                    else
                    {
                        s2 += s1[i];
                    }
                }
            cout << endl;
        }
    }

}

 

标签:map,About,word,string,dictionary,s1,hdu,should,END
From: https://www.cnblogs.com/ruoye123456/p/17008812.html

相关文章

  • Java同步器之辅助类Semaphore
    一、概述Semaphore(信号量)是用来控制同时访问特定资源的线程数量,它通过协调各个线程,以保证合理的使用公共资源。二、使用案例可以用于做流量控制,特别是公用资源有限的应......
  • postgresql批量新增或更新的sql语句(Mapper实现)
    1@Insert({"<script>"+2"<foreachcollection=\"list\"item=\"item\"separator=\";\">"+3"INSERTINTOsc_water_month(\n......
  • applyColorMap()研究(如果我对现有的colormap不满意,那么如何具体来做)
    cv::applyColorMap()能够实现预定义的伪彩色,这个是众所周知的事情。并且和matlab提供的很相近除了这些预置的变换,如果我想实现新的变换,需要做LUT变换:......
  • GO 使用嵌套map应该多次分配空间
    GO使用嵌套map应该多次分配空间demopackagemainimport( "fmt")funcmain(){ //初始化一个map vartmpmap[int64]interface{} //tmp[1]="abc"//pan......
  • new Map() 小实例
    newMap()定义://constmap=newMap();constmap=newMap([[1,2],[{a:1},2],["1",2]]);console.log(map)//Map(3){1=>2,{…}=>2,"1"=>2}......
  • utf-8 - 如何修复 'character map file ` UTF-8' not found'
    正在设置一个UBIrhel8容器。我需要执行这个命令:localedef-fUTF-8-ien_USen_US.UTF-8失败了:charactermapfile`UTF-8'notfound:Nosuchfileordirect......
  • mybatis: Invalid bound statement (not found): com.xxx.mapper.xxxMapper.selectByx
    背景:业务功能开发,新增一些查询功能,对应地创建了一个mapper接口类,一个mapper.xml文件。这个mapper的命名是:Rolemapper.xml(盯着它)什么namespace,方法名都没有名,......
  • Configmap
    百度网盘链接:https://pan.baidu.com/s/15t_TSH5RRpCFXV-93JHpNw?pwd=8od3 提取码:8od315Configmap15.1Configmap概述15.1.1什么是Configmap?Configmap是k8s中的资源......
  • 2021Kali系列 -- BurpSuite(sqlmap插件)
    再等几年我们就在一起上下班,逛超市,做饭,窝在沙发上看电影,在我们自己家里,等我再努力一下。。。---- 网易云热评一、启动BurpSuite,选择Extender--》BApp Store--》SQLiPy s......
  • 2021Kali系列 -- Burpsuite+Sqlmap批量扫描
    我没有被谁好好爱过,所以只要有人对我好一点,我就以为遇到对的人,如果打扰到你,不好意思。。。---- 网易云热评 一、设置BurpSuite,保存日志文件1、选择Project options====......