题意:上部分是单词表,下部分是句子,翻译句子。START开始,END结束。
思路:简单字典树。
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?

InputThe 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.
OutputIn 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.
 1 #include<iostream>
2 #include<map>
3 #include<stdio.h>
4 #include<string.h>
5 using namespace std;
6 int main()
7 {
8 string s,m,e,t;
9 map<string,string>q;
10 while(1)
11 {
12 cin>>t;
13 while(1)
14 {
15 cin>>m;
16 if(m=="END")
17 break;
18 cin>>e;
19 q[e]=m;
20 }
21 cin>>t;
22 s="";
23 getchar();
24 char g[3010]={0};
25 while(1)
26 {
27 gets(g);
28 if(strcmp(g,"END")==0) return 0;
29 int len=strlen(g);
30 for(int i=0;i<len;i++)//遍历这个句子
31 {
32 if(g[i]<'a'||g[i]>'z')
33 //当前字符不是字母,证明单词结束
34 {
35 if(q[s]!="")
36 //如果字典中有这个单词,输出对应字符串
37 {
38 cout<<q[s];
39 }
40 else//字典中没有这个单词,则输出单词
41 cout<<s;
42 s="";//情况字符串,准备储存下一个单词
43 cout<<g[i];//输出当前不是字母的字符
44 }
45 else//当前字符是字母时
46 s+=g[i];//将字母存到字符串中
47 }
48 cout<<endl;
49 }
50 }
51 }

J - What Are You Talking About(map,字典树)的更多相关文章

  1. poj 2503 哈希 Map 字典树

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36967   Accepted: 15749 Descr ...

  2. hdu1247-Hat’s Words-(字典树)

    http://acm.hdu.edu.cn/showproblem.php?pid=1247 题意:给出一堆单词,求哪些单词是其中某两个单词拼接起来的. 题解:用字典树存储所有的单词,标记结束点,再次 ...

  3. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  4. kmp&字典树 模板

    kmp: const int maxn=1e5+5; char s[maxn],p[maxn]; int nex[maxn]; int KmpSearch(char* s, char* p) { in ...

  5. hdu1251 字典树or map

    一道字典树的题,不过看起来用map更为简单 传送门 题意: 给出一堆字符串构成一个字典,求字典里以某字符串为前缀的字符串有几个 思路: 输入字符串时把字符串的前缀全部存进map并标记次数 查询时直接输 ...

  6. I: Carryon的字符串排序(字典树/map映射)

    2297: Carryon的字符串 Time Limit: C/C++ 1 s      Java/Python 3 s      Memory Limit: 128 MB      Accepted ...

  7. POJ 1002 487-3279(字典树/map映射)

    487-3279 Time Limit: 2000MS        Memory Limit: 65536K Total Submissions: 309257        Accepted: 5 ...

  8. TOJ3097: 单词后缀 (字典树 or map瞎搞)

    传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...

  9. HDU 1247 Hat’s Words (字典树 &amp;&amp; map)

    分析:一開始是用递归做的,没做出来.于是就换了如今的数组.即,把每个输入的字符串都存入二维数组中,然后创建字典树.输入和创建完成后,開始查找. 事实上一開始就读错题目了,题目要求字符串是由其它两个输入 ...

随机推荐

  1. fastjsion反序列化漏洞渗透测试笔记

    本文原创地址:https://www.cnblogs.com/yunmuq/p/14268028.html 一.背景 fastjsion是阿里的开源Java工具:https://github.com/ ...

  2. 图片质量评估论文 | 无监督SER-FIQ | CVPR2020

    文章转自:同作者微信公主号[机器学习炼丹术].欢迎交流,共同进步. 论文名称:SER-FIQ: Unsupervised Estimation of Face Image Quality Based ...

  3. .NET 云原生架构师训练营(模块二 基础巩固 RabbitMQ Masstransit 异常处理)--学习笔记

    2.6.8 RabbitMQ -- Masstransit 异常处理 异常处理 其他 高级功能 异常处理 异常与重试 重试配置 重试条件 重新投递信息 信箱 异常与重试 Exception publi ...

  4. Desired_Capabilities配置

    appium服务器初始化参数 最全: https://github.com/appium/appium/blob/master/docs/cn/writing-running-appium/caps. ...

  5. Python基础语法4-运算符

    Python提供了一系列丰富的运算符,包括:  Ø算术运算符  Ø赋值运算符  Ø关系运算符  Ø逻辑运算符 Ø位运算符  Ø三元运算符 Ø身份运算符 Ø成员运算符

  6. JDBC入门程序总结

    JDBC本质 只是一个接口 每个数据库的规范 就是实现类的接口 其实是官方 定义的一套操作所有关系型数据库的规则,就是接口,各个数据库厂商去实现这套接口,提供数据库驱动jar包, 我们可以使用这套接口 ...

  7. 洛谷P1972 [SDOI2009]HH的项链(树状数组)

    题目链接: https://www.luogu.org/problemnew/show/P1972 题目描述: HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后 ...

  8. docker mysql 设置忽略大小写

    使用docker 安装mysql时  Linux下是默认不忽略大小写,导致操作数据库的时候会报如下错误 为了解决上面的问题,我们在创建MySQL容器的时候就需要初始化配置  lower_case_ta ...

  9. [从源码学设计]蚂蚁金服SOFARegistry之延迟操作

    [从源码学设计]蚂蚁金服SOFARegistry之延迟操作 0x00 摘要 SOFARegistry 是蚂蚁金服开源的一个生产级.高时效.高可用的服务注册中心. 本系列文章重点在于分析设计和架构,即利 ...

  10. 大数据系列2:Hdfs的读写操作

    在前文大数据系列1:一文初识Hdfs中,我们对Hdfs有了简单的认识. 在本文中,我们将会简单的介绍一下Hdfs文件的读写流程,为后续追踪读写流程的源码做准备. Hdfs 架构 首先来个Hdfs的架构 ...