题意:

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

分析:

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

#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. sql之独立子查询和相关子查询总结

    1.独立子查询:顾名思义:就是子查询和外层查询不存在任何联系,是独立于外层查询的: 下面就看一个例子: 有一张订单表 Sales.Order 和一张 客户表 Sales.Customer 下面的sql ...

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

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

  3. The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemK:K-Nice

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3212 题意:构造出一个n*m的有k个上下左右的和等于中间数的小矩阵的任意矩 ...

  4. HDU1465+递推

    经典的信封装信问题 f[ n ]  = ( n-1 ) * ( f[ n-1 ]+f[ n-2 ] ) #include<stdio.h> #include<string.h> ...

  5. linux为命令取别名

    在linux的命令中,有些命令很长并且经常使用到,我们可以为命令添加一个别名,格式如下: $ alias 别名='命令' 例如: # 列出home文件夹的文件 $ alias lsh='ls -l / ...

  6. mvc学习

    视频: http://edu.51cto.com/index.php?do=lession&id=14581 博客: http://www.cnblogs.com/chsword/archiv ...

  7. 【BZOJ 1046】 1046: [HAOI2007]上升序列

    1046: [HAOI2007]上升序列 Description 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < ...

  8. H264码流解析及NALU

    ffmpeg 从mp4上提取H264的nalu http://blog.csdn.net/gavinr/article/details/7183499 639     /* bitstream fil ...

  9. Qt串口通信接收数据不完整的解决方法(传输图片)

    在使用串口接收数据时,当数据量大的时候会出现数据接收不完整的情况.因为串口数据获取函数readAll()由readyRead()信号触发,但readyRead()信号在串口读到起始标志时立即发送,并不 ...

  10. Smallest unused ID

    http://www.codewars.com/kata/smallest-unused-id Description: Hey awesome programmer! You've got much ...