hdu 1075 What Are You Talking About 火星文翻译成英文
What Are You Talking About
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?
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.
一、map
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<cctype>
using namespace std;
map<string,string>p;
string a,b,s,ss;
int main()
{
cin>>s;
while(cin>>a)//输入对照表
{
if(a=="END")
break;
else
{
cin>>b;
p[b]=a;
}
}
cin>>s;
getchar();//这里要接收一个回车,否则会格式错误
while(getline(cin,a))
{
if(a=="END")
break;
else
{
int len=a.length();
for(int i=;i<len;i++)
{
if(isalpha(a[i]))//判断是否是字母
{
ss=ss+a[i];
if(!isalpha(a[i+]))
{
if(p[ss]!="")//如果是火星文,输出对应的匹配值
cout<<p[ss];
else//原文直接输出
cout<<ss;
ss.clear();
}
}
else
cout<<a[i];
}
}
cout<<endl;
}
return ;
}
二、字典树
#include<iostream>
#include<string.h>
#include<string>
#include<cctype>
using namespace std;
int tree[][],vis[];
int cnt=,id,len,root,num=;
string s,ss,a[],b;
void insert()
{
root=;
len=b.length();
for(int i=;i<len;i++)
{
id=b[i]-'a';
if(!tree[root][id])
tree[root][id]=++num;
root=tree[root][id];
}
vis[root]=cnt;
} int search(string ss)
{
root=;
len=ss.length();
for(int i=;i<len;i++)
{
id=ss[i]-'a';
if(!tree[root][id])
return ;
root=tree[root][id];
}
return vis[root];
}
int main()
{
cin>>s;//输入STAR
while(cin>>a[cnt])
{
if(a[cnt]=="END")
break;
cin>>b;
insert();
cnt++;
}
cin>>s;
getchar();
while(getline(cin,b))
{
if(b=="END")
break;
for(int i=;i<b.length();i++)
{
if(isalpha(b[i]))
{
ss=ss+b[i];
if(!isalpha(b[i+]))
{
int t=search(ss);
if(t==)//原文
cout<<ss;
else
cout<<a[t];
ss.clear();
}
}
else
cout<<b[i];
}
cout<<endl;
}
}
hdu 1075 What Are You Talking About 火星文翻译成英文的更多相关文章
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the lan ...
- hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- 题解报告:hdu 1075 What Are You Talking About
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 Problem Description Ignatius is so lucky that he ...
- 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 ...
- [.ashx檔?泛型处理例程?]基础入门#1....能否用中文教会我?别说火星文?
原文出處 http://www.dotblogs.com.tw/mis2000lab/archive/2013/08/20/ashx_beginner_01.aspx [.ashx檔?泛型处理例程? ...
- hdu 1075 (map)
http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...
- hdu 1075 What Are You Talking About
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:比较简单,易懂,这里不做说明. 解法:第一种方法:用map映射,耗时1000+ms:第二种 ...
- 字典树 HDU 1075 What Are You Talking About
http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}
- 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 ...
随机推荐
- web阶段乱码问题
一,概述 1.为什么会出现乱码问题 因为客户端(浏览器)和服务器端的编码和解码不一致. 我们web阶段都是围绕请求响应机制展开的, 客户端请求服务器,服务器给客户端做出响应 . 也就意味着客户端和服务 ...
- ch4 圆角框
固定宽度的圆角框 只需要两个图像:一个应用于框的顶部,一个应用于底部 <div class="box"> <h2>Lorem Ipsum</h2> ...
- 拦截指定数据、修改JS -- mitmproxy
mitmproxy 配置 mitmproxy源码:https://github.com/mitmproxy/mitmproxy mitmdump -q:屏蔽mitmdump默认的控制台日志,只显示自己 ...
- iOS Burp suite CA证书 HTTPS
设置好burp suite代理后,在浏览器地址输入http://burp/,下载CA证书: 在iOS上下载CA证书,可通过邮件或百度云等一切iOS可以访问证书文件的方法: 点击证书文件iOS提示安装, ...
- Vivado ILA观察信号和调试过程
先简单介绍一下ILA(Integrated Logic Analyzer)生成方法.这里有两种办法完成Debug Core的配置和实现. 方法一.mark_debug综合选项+Set Up Debug ...
- 记一次菜鸡的低级折腾--WordPress get Webshell(后台文件编辑插马)
挺简单的一个测试站,开始思路错了,一直去网上找WordPress的漏洞,看有没有什么能利用的,未果,因为这个测试站有些地方并不完善,有的漏洞利用不了,菜鸡的我连弱口令都没猜对,没知识就是这么悲哀. 下 ...
- Net Core3.1 添加 Swagger
一.为什么使用Swagger 随着互联网技术的发展,现在的网站架构基本都由原来的后端渲染,变成了:前端渲染.后端分离的形态,而且前端技术和后端技术在各自的道路上越走越远. 前端和后端的唯一联系,变成了 ...
- Typora: Markdown Reference (Typora下Markdown语法使用说明)
引言 由于一直在使用Typora,这个是我使用过的最棒的Markdown编辑器,但是总是忽略某一个功能,于是决定认真看一下其帮助文档 这里做一个简单主要功能的中文翻译(按键对应Windows下). 标 ...
- Windows环境下的32位汇编语言程序设计
一个逆向的告诉我可以尝试学一下8086处理器,再回头看一看自己学过的会有提高学呗,8086处理器怎么学....然后就学了8086的汇编, 好友就分享了琢石成器——Windows环境下的32汇编语言设计 ...
- pt-archiver 归档数据
pt-archiver 参数说明pt-archiver是Percona-Toolkit工具集中的一个组件,是一个主要用于对MySQL表数据进行归档和清除工具.它可以将数据归档到另一张表或者是一个文件中 ...