J - What Are You Talking About(map,字典树)
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,字典树)的更多相关文章
- poj 2503 哈希 Map 字典树
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36967 Accepted: 15749 Descr ...
- hdu1247-Hat’s Words-(字典树)
http://acm.hdu.edu.cn/showproblem.php?pid=1247 题意:给出一堆单词,求哪些单词是其中某两个单词拼接起来的. 题解:用字典树存储所有的单词,标记结束点,再次 ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- kmp&字典树 模板
kmp: const int maxn=1e5+5; char s[maxn],p[maxn]; int nex[maxn]; int KmpSearch(char* s, char* p) { in ...
- hdu1251 字典树or map
一道字典树的题,不过看起来用map更为简单 传送门 题意: 给出一堆字符串构成一个字典,求字典里以某字符串为前缀的字符串有几个 思路: 输入字符串时把字符串的前缀全部存进map并标记次数 查询时直接输 ...
- I: Carryon的字符串排序(字典树/map映射)
2297: Carryon的字符串 Time Limit: C/C++ 1 s Java/Python 3 s Memory Limit: 128 MB Accepted ...
- POJ 1002 487-3279(字典树/map映射)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 309257 Accepted: 5 ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- HDU 1247 Hat’s Words (字典树 && map)
分析:一開始是用递归做的,没做出来.于是就换了如今的数组.即,把每个输入的字符串都存入二维数组中,然后创建字典树.输入和创建完成后,開始查找. 事实上一開始就读错题目了,题目要求字符串是由其它两个输入 ...
随机推荐
- 双重校验锁 --使用volatile和两次判空校验
介绍 双重校验锁是单例模式中,饿汉式的一种实现方式.因为有两次判空校验,所以叫双重校验锁,一次是在同步代码块外,一次是在同步代码块内. 为什么在同步代码块内还要再检验一次? 第一个if减少性能开销,第 ...
- 如何在面试中介绍自己的项目经验(面向java改进版)
本人于3年前写的博文,如何在面试中介绍自己的项目经验,经过大家的捧场,陆续得到了将近7万个点击量,也得到了众多网站公众号的转载,不过自己感觉,这篇文章更多的是偏重于方法,没有具体给到Java方面相关的 ...
- linux安装ftp步骤
1,查看是否安装了FTP:rpm -qa |grep vsftpd 2,如果没有安装,可以使用如下命令直接安装 yum -y install vsftpd 默认安装目录:/etc/vsftpd 3,添 ...
- SQLI-LABS复现通关
sql-lab 复现通关(深入学习) less-1 基于错误的单引号字符串 - 正常访问 127.0.0.1/?id=1 - 添加 ' 返回报错信息:You have an error in your ...
- drop table 命令不回收以前的相关访问权限
drop table 命令不回收以前的相关访问权限,也就是说假如我现在把表删除了,然后再创建一个同名的表时,会自动赋予权限的.
- 【Oracle】权限相关
系统权限 SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE = 'CHAXUN' UNION ALL SELECT * FROM DBA_SYS_PRIVS WHER ...
- dblink查找对应的目标端session
v$session试图中process字段代表的是客户端所在机器的进程号 例如我使用toad连接数据库,查询到的process即toad的进程号 SELECT process FROM V$SESSI ...
- const关键字:终于拥有真正的常量声明语句
本文首发于个人网站:const关键字:终于拥有真正的常量声明语句 你好,今天大叔想和你唠扯唠扯 ES6 新增的关键字 -- const.在说 const 关键字之前,大叔先和你唠唠大叔自己对 cons ...
- Java面试官经验谈:如何甄别候选人真实的能力,候选人如何展示值钱技能
我做Java方面的面试官也有些年头了,从校招学生到初级开发到架构师我都面试过.从技术上来讲,候选人通过面试的标准可能千差万别,但归结成一句话,就是候选人达到了职位介绍的要求,且相关项目经验达到足量的年 ...
- 使用remix实现给合约账户转账
实现内容:从remix上的虚拟账户上转账给自己编写的智能合约账户 前提基础:对solidity有一些基础了解,对以太坊的账户机制有一定了解. 账户 在以太坊中账户的唯一标识是地址(address). ...