What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 31176    Accepted Submission(s): 10700

Problem Description
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?
 
Input
The
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.
 
Output
In 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!
 
题意:第一个SATR到END之间,输入火星文翻译表,第二个SATR到END之间,输入多句火星文,要求你翻译输出
题解:
1、map(string,string)
2、字典树,在输入火星文翻译表时建树,在每建完一个火星文单词,就在后面记录对应翻译单词的下标
 

一、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 火星文翻译成英文的更多相关文章

  1. 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 ...

  2. hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  3. 题解报告:hdu 1075 What Are You Talking About

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 Problem Description Ignatius is so lucky that he ...

  4. 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 ...

  5. [.ashx檔?泛型处理例程?]基础入门#1....能否用中文教会我?别说火星文?

    原文出處  http://www.dotblogs.com.tw/mis2000lab/archive/2013/08/20/ashx_beginner_01.aspx [.ashx檔?泛型处理例程? ...

  6. hdu 1075 (map)

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...

  7. hdu 1075 What Are You Talking About

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:比较简单,易懂,这里不做说明. 解法:第一种方法:用map映射,耗时1000+ms:第二种 ...

  8. 字典树 HDU 1075 What Are You Talking About

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}

  9. 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 ...

随机推荐

  1. GPU运行Tensorflow的几点建议

    1.在运行之前先查看GPU的使用情况: 指令:nvidia-smi 备注:查看GPU此时的使用情况 或者 指令:watch nvidia-smi 备注:实时返回GPU使用情况 2.指定GPU训练: 方 ...

  2. 移动端触摸touchstart监听事件

    click.mousedown等事件适用于PC端,在移动端会有一定时间的延迟,所以更好的优化移动端体验,要用touch事件, 1.首先要添加一个监听事件,监听移动端行为 element.addEven ...

  3. 信号强度(RSSI)知识整理

    来源: https://www.cnblogs.com/lele/articles/2832885.html 为什么无线信号(RSSI)是负值 答:其实归根到底为什么接收的无线信号是负值,这样子是不是 ...

  4. Linux centosVMware 磁盘格式化、磁盘挂载、手动增加swap空间

    一.磁盘格式化 磁盘分区后不能直接使用,需要对每一个分区格式化,格式化其实就是安装系统文件. 命令mke2fs:不支持格式化成xfs系统文件  mkfs.ext4 == mke2fs -t ext4 ...

  5. vim的几种模式

    Normal Mode 普通模式 功能:在这种模式下可以移动光标等. 进入:默认进入vim之后,处于这种模式.在其他模式下狂按ESC后进入此模式. Visual Mode 可视模式 功能:在这种模式下 ...

  6. 03WebDriver

    概述 WebDriver一般用于测试 执行脚本 1.驱动包  WebDriver  不同的浏览器不同的驱动包 2.驱动包技术一个chrome.exe的程序,放到环境变量中,一般放在C:windows里 ...

  7. CodeForces - 862C Mahmoud and Ehab and the xor(构造)

    题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x. 分析: 1.因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ...

  8. Android拷贝工程不覆盖原工程的配置方法

    http://www.2cto.com/kf/201203/125131.html 在Eclipse中改包名的时候选择refactor-->rename,勾选Rename subpackages ...

  9. java面试题汇总,不断更新中。。。

    JVM,并发,锁相关: 1.请你谈谈对volatile的理解,volatile是否存在伪共享问题. 2.cas你知道吗? 3.原子类AtomicInteger的ABA问题谈谈?原子更新引用知道吗? 4 ...

  10. sed的妙用

    sed 使用-n选项和p可以实现在指定范围内的搜索貌似实现了比grep更精确的搜索