题意:

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

分析:

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

#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. HTML元素大小和位置相对于谁的问题

    一.如果元素的position属性值为absolute,那么此时分为两种情况: 1. 父级(包括直接父级和间接父级)元素中没有定义position属性(即默认属性static),那么该元素会参照页面, ...

  2. jquery bind()方法与live()方法的区别

    jquery bind() 方法和 live() 方法都可以绑定元素事件. <!DOCTYPE html> <html> <head> <meta chars ...

  3. Unity3D的几种坐标系

    原地址:http://www.cnblogs.com/martianzone/p/3371789.html http://www.cnblogs.com/88999660/archive/2013/0 ...

  4. 快速排序(quicksort)算法实现

    快速排序(quicksort)是分治法的典型例子,它的主要思想是将一个待排序的数组以数组的某一个元素X为轴,使这个轴的左侧元素都比X大,而右侧元素都比X小(从大到小排序).然后以这个X在变换后数组的位 ...

  5. web机制简笔

    1 Web 1.1输入url地址 1.1.1服务器进行url解析,调用相关服务处理,返回处理结果—字符串 1.2得到返回字符串(显示描述+操作触发描述) 1.3Internet explore进行相关 ...

  6. secureCRT中文字符乱码

    1.远程linux机器.修改环境变量LANG.例如在~/.bash_profile里面添加 export LANG=zh_CN.UTF8 2.本地windows机器.修改SecureCRT的设置.找到 ...

  7. linux ubuntu删除引导 grub出现错误解决方案

    使用u盘启动PE系统 找到diskgenius软件,点击: 硬盘->重建主引导记录

  8. 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)

    2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...

  9. Android ActionBar通过Tab进行不同的Fragment之间的交换

    ActionBar的使用常见于4.0系统,其Tab的使用挺广泛的. 在ActionBar中添加标签(Tabs),每个标签对应的是一个Fragment,点击不同的Tab时,就会切换到对应的Fragmen ...

  10. P73、面试题9:斐波那契数列

    题目一:写一个函数,输入n,求斐波那契数列(Fibonacci)数列的第n项,斐波那契数列的定义如下: f(n) = {0  n = 0;  1   n = 1;  f(n-1)+f(n-2)  n& ...