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 ...
随机推荐
- 9月Win10杀软大PK
导读 严格来说,Windows 10 并不存在“裸奔”一说,因为自带的 Defender 安全中心已经是越来越强大. 来自独立机构 AV-Comparatives 的 9 月份评测报告显示,Windo ...
- css 瀑布流
瀑布流 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...
- sentinel控制台
下载sentinel源码包:https://github.com/alibaba/Sentinel/tree/master,根据自己需要下载不同版本的分支,博主下载得是1.6 下载后解压,然后进入se ...
- 【Linux】centos7下解决yum -y install mysql-server 没有可用包
第一步:安装从网上下载文件的wget命令 [root@localhost ~]# yum -y install wget 第二步:下载mysql的repo源 [root@localhost ~]# w ...
- js原型链。。fuck
function Person(name){ this.name = name; }; function Mother(){ }; //给mother提供公有的属性 Mother.prototype ...
- SpringBoot Date类型插入数据库始终比正确时间早一天问题解决办法
bug描述 昨天的Date插入不进去问题解决后,一直没发现其实插入的时间一直比正确的时间早一天 输出sql语句,发现insert语句还是对的,不知道为什么插入数据库之后结果就早了一天 https:// ...
- JDBC--获取数据库连接
1.JDBC(Java Database Connectivity)是一个独立于特定数据库管理系统.统一的sQL数据库存取和操作的公共接口. 2.Java中的几种数据库存取技术: --1)JDBC直接 ...
- MyEclipse 8.6.1 制作绿色版
我们先在这个目录下新建一个文件: MyEclipse 10.6.bat , 文件内容如下: start eclipse\eclipse.exe -vm jre\bin\javaw.exe 接下来只需要 ...
- mysql分区介绍
http://www.cnblogs.com/chenmh/p/5644713.html 介绍 可以针对分区表的每个分区指定各自的存储路径,对于innodb存储引擎的表只能指定数据路径,因为数据和索引 ...
- java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)(转)
Caused by: java.io.FileNotFoundException: rmi_keystore.jks (没有那个文件或目录) 解决方法:修改jmeter.properites: ser ...