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. (二)Buildroot介绍

    详情请参考: http://www.buildroot.org/downloads/manual/manual.html 参考博客: https://www.cnblogs.com/arnoldlu/ ...

  2. Android 用ViewFlipper实现跑马灯效果的公告提示

    1.代码部分private void initViewFlipper(final HomepageListModel.Notice notice) { for (int i = 0; i < n ...

  3. vue 组件 - 函数统一调用(自定义钩子)

    vue 组件继承方法 var childComponent = Vue.extend( { extends: baseComp, // 继承基础组件方法 template:template, wait ...

  4. luogu P2762 太空飞行计划问题

    好像是最大权闭合图,也就是最大流最小割啦,找出最大流的路径输出,这题如何建模呢,一样的先设源点和汇点,源点向每个计划连capacity为赞助数的边,每个计划连相应装置capacity为无穷的边,每个装 ...

  5. WDSL文件中的XML元素

    WDSL文件中的XML元素 理解起来其实很简单Types指定类型,当然是在后面的Message中需要的类型Message可以理解为函数中的参数,只不过如果一个函数如果有多个参数的时候应该吧这些参数定义 ...

  6. AssetBundle打包依赖(宽宽又欠我一顿烧烤)

    using UnityEngine; using System.Collections; using UnityEditor; public class dabao : EditorWindow { ...

  7. JForum项目搭建

    JForum 是采用Java开发的功能强大且稳定的论坛系统.它提供了抽象的接口.高效的论坛引擎以及易于使用的管理界面,同时具有完全的权限控制.多语言支持(包括中文).高性能.可自定义的用户接口.安全. ...

  8. 如何给谷歌浏览器安装vue-devtools插件

    感谢原作者:https://www.cnblogs.com/alice-fee/p/8038367.html 安装方法1: 需正常打开chrome商店,搜索vuejs devtools 安装.chro ...

  9. Mozilla Firefox 68 正式发布下载:对刚Chrome

    Mozilla Firefox 68开源和跨平台Web浏览器现在正式发布,可以下载适用于GNU/Linux,Mac和Windows平台的Firefox 68了. Firefox 68网络浏览器现在可以 ...

  10. hadoop安装文档

    一.准备 该准备工作在三台机器上都需要进行,首先使用 vmvare 创建 1 个虚拟机,这台虚拟机是 master,一会需要把 master 克隆出两台 slave 点确定然后开启此虚拟机 然后添加/ ...