题意:

给你一个字典 一个英文单词对应一个火星单词 给你一段火星文翻译成英文 字典上的没有的不翻译

分析:

没有给数据规模 字典树用链表

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int maxn = 1e5+;
const int mod = ;
struct trie{
string tran;
trie *next[];
};
trie *root;
void init(){
root=new trie;
root->tran[]='*';
for(int i=;i<;++i)
root->next[i]=NULL;
}
void build(string eng,string mar){
int l=mar.length();
trie *p=root;
for(int i=;i<l;++i){
int tmp=mar[i]-'a';
if(p->next[tmp]==NULL){
p->next[tmp]=new trie;
p=p->next[tmp];
p->tran[]='*';
for(int j=;j<;++j)
p->next[j]=NULL;
}
else{
p=p->next[tmp];
}
}
p->tran=eng;//存对应的英文单词
}
void dele(trie *root){
for(int i=;i<;++i){
if(root->next[i]!=NULL)
dele(root->next[i]);
}
delete(root);
}
string query(string mar){
int l=mar.length();
trie *p=root;
for(int i=;i<l;++i){
int tmp=mar[i]-'a';
if(p->next[tmp]==NULL)return mar;//没查到
p=p->next[tmp];
}
if(p->tran[]=='*')return mar;
return p->tran;
}
int main()
{
init();
string s1,s2;
while(cin>>s1){
if(s1=="START")continue;
if(s1=="END")break;
cin>>s2;
build(s1,s2);
}
getchar();
while(getline(cin,s1)){
if(s1=="START")continue;
if(s1=="END")break;
string str1="",str2="";
for(int i=;i<s1.length();++i){
if(s1[i]>='a'&&s1[i]<='z'){
str1+=s1[i];
}
else{
str2+=query(str1);
str1="";
str2+=s1[i];
}
}
cout<<str2<<endl;
}
// dele(root);
return ;
}

HDU 1075-What Are You Talking About(Trie)的更多相关文章

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

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

  3. HDU 1075 What Are You Talking About (strings)

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

  4. hdu 1075 What Are You Talking About(map)

    题意:单词翻译 思路:map #include<iostream> #include<stdio.h> #include<string.h> #include< ...

  5. 【python】Leetcode每日一题-前缀树(Trie)

    [python]Leetcode每日一题-前缀树(Trie) [题目描述] Trie(发音类似 "try")或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的 ...

  6. HDU 1052 Tian Ji -- The Horse Racing(贪心)(2004 Asia Regional Shanghai)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Ch ...

  7. HDU 1087:Super Jumping! Jumping! Jumping!(LIS)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)

    统计难题Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submis ...

  9. HDU 1671 Phone List (Trie)

    pid=1671">Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. HDU 1358 Period (kmp求循环节)(经典)

    <题目链接> 题目大意: 意思是,从第1个字母到第2字母组成的字符串可由某一周期性的字串(“a”) 的两次组成,也就是aa有两个a组成: 第三行自然就是aabaab可有两个aab组成: 第 ...

随机推荐

  1. jQuery的on方法和bind绑定多个事件

    on方法是官方推荐使用的方法比较新 1. on: 多个事件绑定同一个函数 $(document).ready(function(){ $("p").on("mouseov ...

  2. xcode 6.3 打包crash问题--参考

    xcode升级6.3之后,有些项目会出现打包crash的问题,只要选择偏好设置,把source control全部禁用掉就可以了.

  3. bnu 4352 XsugarX的疯狂按键识别(暴力模拟)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=4352 [题意]:给你个长串,输出该长串中能第一放出的技能,每个技能有对应的一个小子串,不能放出任何技 ...

  4. 1020: [SHOI2008]安全的航线flight - BZOJ

    Description在设计航线的时候,安全是一个很重要的问题.首先,最重要的是应采取一切措施确保飞行不会发生任何事故,但同时也需要做好最坏的打算,一旦事故发生,就要确保乘客有尽量高的生还几率.当飞机 ...

  5. 15个带示例的jQuery滚动条插件

    1.NiceScroll:可用于桌面.移动与触摸设备的jQuery滚动插件 NiceScroll是一个jQuery插件(since 1.5),它有着类似于ios/移动设备的样式.它支持Div.iFra ...

  6. PAT-乙级-1036. 跟奥巴马一起编程(15)

    1036. 跟奥巴马一起编程(15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 美国总统奥巴马不仅呼吁所有人 ...

  7. Good Bye 2015B

    Problem B:http://codeforces.com/contest/611/problem/B B. New Year and Old Property 题意:问输入的年份a到b中转化为二 ...

  8. linux ubuntu关于U盘的安装 开机启动u盘的时候出现/casper/vmlinuz.efi: file not found

    将u盘下的/casper/vmlinuz文件添加一个后缀.efi即可. 重启再装.

  9. linux命令补全 忘记命令只记得开头

    linux的shell不仅提供上下箭头来翻阅历史使用过的命令,还提供命令补全功能. 例如,你想创建一个文件夹,只记得是m开头的命令,此时可以: ①输入m ②按键盘上的Tab键两次 (有可能还出现这句话 ...

  10. Zookeeper + Hadoop + Hbase部署备忘

    网上类似的文章很多,本文只是记录下来备忘.本文分四大步骤: 准备工作.安装zookeeper.安装hadoop.安装hbase,下面分别详细介绍: 一 准备工作 1. 下载 zookeeper.had ...