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 ...
 
随机推荐
- Spring之byte[]传输
			
事出原因 某些原因,需要在在服务之间传输文件,想到只有通过Byte数组,或者是Stream传递,遂定下两方法,一个byte,一个inpustream,老样子,upload(@RequestParam( ...
 - 提高 Java 代码性能的各种技巧
			
Java 6,7,8 中的 String.intern – 字符串池 这篇文章将要讨论 Java 6 中是如何实现 String.intern 方法的,以及这个方法在 Java 7 以及 Java 8 ...
 - tomcat点击startup.bat出现闪退,启动不成功的解决办法
			
问题描述:tomcat点击startup.bat出现命令行闪退的情况 打开startup.bat,在第一行加入 SET JAVA_HOME=D:\jdk\jdk1.8.0_121[jdk路径] SET ...
 - 对于strlen()函数的一点小疑问
			
看csapp时候,看一下char*[8],以为char*也是一字节,但是指针是地址,64位编译器下是8字节,所以sizeof(B)是64字节 后来又看strlen(). #include"s ...
 - java校招一些面试的题目
			
数组和链表的区别 数组静态分配内存,链表动态分配内存: 数组在内存中连续,链表不一定连续: 数组元素在栈区,链表元素在堆区: 数组利用下标定位,时间复杂度为O(1),链表定位元素时间复杂度O(n) 数 ...
 - APP自动化测试获取包名的两种方法
			
获取包名的两种方法: 一.通过aapt获取 1.进入aapt.exe所在路径 2.在地址栏输入cmd回车,打开dos命令窗口. 3.在命令窗口输入 aapt dump badging 拖入apk 回车 ...
 - MQTT v5 (MQTT 5.0) 新特性介绍
			
https://blog.csdn.net/mrpre/article/details/87267400 背景 MQTT v3.1.1 作为一个经典的版本,一般能够满足大部分需求:为了避免落后,我们也 ...
 - Mapreduce实例——WordCount
			
实验步骤 切换目录到/apps/hadoop/sbin下,启动hadoop. cd /apps/hadoop/sbin ./start-all.sh 2.在linux上,创建一个目录/data/map ...
 - 回过头来看一看过去20年的十大IT趋势
			
导读 这是一个概念,不是一个事物.其实,可以认为当组织的数据增长速度超过IT部门的管理能力时,大数据就开始了.此前,计算机部门的工作人员过去常常按时下班,除非是在灭火或编写代码的时候.而现在,数据管理 ...
 - 解决win10创建Django工程,运行django-admin.py startproject 工程名,失败的问题
			
在看我这篇教程的前提是你应该已经正确装好python和Django了,好了,废话不说了,正题走你!你现在是不是很纠结自己运行django-admin.py startproject 工程名 ...