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

题意 : 给一个单词表然后给一些单词,要求翻译单词表中有的单词,没有则直接输出原单词.
翻译文段部分getchar()输入即可,需要仔细一点,但是很简单不恶心
代码

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const double eps=1e-;
const long long modn=;
struct tri{
bool exist;
int next[];
char ch[];
}e[maxn*];
int tot=;
char a[]={},b[]={},cc;
char st[]={'S','T','A','R','T'};
char ed[]={'E','N','D'};
void doit(int x,int k,int j){
if(k<j){
e[x].exist=;
strcpy(e[x].ch,b);
return;
}
int z=a[j]-'a';
if(e[x].next[z]){
doit(e[x].next[z],k,j+);
}else{
e[x].next[z]=++tot;
doit(tot,k,j+);
}
}
bool getit(int x,int k,int j){
if(k<j){
if(e[x].exist){
printf("%s",&e[x].ch);
return ;
}
return ;
}
int z=a[j]-'a';
if(e[x].next[z]){
return getit(e[x].next[z],k,j+);
}else{
return ;
}
}
int main(){
while(scanf("%s",&b)){
if(strcmp(b,st)==){
continue;
}if(strcmp(b,ed)==){
break;
}
scanf("%s",&a);
doit(,strlen(a)-,);
}
scanf("%s",&b);
a[]=getchar();
a[]=getchar();
int i=;
while(a[]!='E'){
while(a[i]<='z'&&a[i]>='a'){
i++;
a[i]=getchar();
}
cc=a[i];
a[i]=;
if(i>){
if(!getit(,i-,)){
for(int j=;j<i;j++){
printf("%c",a[j]);
}
}
}
printf("%c",cc);
i=;
a[]=getchar();
}
return ;
}

HDU 1057 What Are You Talking About trie树 简单的更多相关文章

  1. HDU 11488 Hyper Prefix Sets (字符串-Trie树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

  2. HDU1251 统计难题 trie树 简单

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 找前缀数量 裸模板 #include<cstdio> #include<cstr ...

  3. AVL树,红黑树,B-B+树,Trie树原理和应用

    前言:本文章来源于我在知乎上回答的一个问题 AVL树,红黑树,B树,B+树,Trie树都分别应用在哪些现实场景中? 看完后您可能会了解到这些数据结构大致的原理及为什么用在这些场景,文章并不涉及具体操作 ...

  4. HDU 1251 Trie树模板题

    1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...

  5. HDU 5269 ZYB loves Xor I Trie树

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5269 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  6. hdu 5269 trie树

    现场想到了lowbit(X xor Y)=X和Y从右向左数,对应相同的数的个数+1...然而并没有想到接下来用trie树 然后就想排个序试试...然后就整个人都不好了啊摔 sol:用trie,一边in ...

  7. hdu 4099 Revenge of Fibonacci Trie树与模拟数位加法

    Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输 ...

  8. HDU 1251 统计难题 (字符串-Trie树)

    统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...

  9. 【HDU - 5790 】Prefix(主席树+Trie树)

    BUPT2017 wintertraining(15) #7C 题意 求[min((Z+L)%N,(Z+R)%N)+1,max((Z+L)%N,(Z+R)%N)+1]中不同前缀的个数,Z是上次询问的结 ...

随机推荐

  1. 【CodeForces】947 D. Picking Strings

    [题目]D. Picking Strings [题意]给定只含'A','B','C'的字符串,支持以下变换:1.A - BC   2.B - AC   3.C - AB   4.AAA - empty ...

  2. POJ - 1330 Nearest Common Ancestors 最近公共祖先+链式前向星 模板题

    A rooted tree is a well-known data structure in computer science and engineering. An example is show ...

  3. node、npm及node_modules中依赖的版本更新

    好久没用node了,想重新拾起来发现node还有相关模块的版本都太低了,使用npm install全是报版本低的警告. 这里记录一下,版本管理和node_modules更新的方法. 我用的是Windo ...

  4. 2017ACM暑期多校联合训练 - Team 7 1010 HDU 6129 Just do it (找规律)

    题目链接 Problem Description There is a nonnegative integer sequence a1...n of length n. HazelFan wants ...

  5. 用js拼接url为pathinfo模式

    用js拼接url为pathinfo模式

  6. Coursera在线学习---第四节.过拟合问题

    一.解决过拟合问题方法 1)减少特征数量 --人为筛选 --靠模型筛选 2)正则化(Regularization) 原理:可以降低参数Θ的数量级,使一些Θ值变得非常之小.这样的目的既能保证足够的特征变 ...

  7. 一起来学redis(一)

    redis是一个开源的,高性能的,基于键值对的缓存与存储系统通过提供多种键值数据类型来适应不同场景下的缓存与存储需求. 同时redis的诸多高层级功能使其可以胜任消息队列,任务队列等不同的角色. 特性 ...

  8. Class.this 和 this 的有什么不同

    转载:http://www.cnblogs.com/liwei45212/archive/2013/04/17/3026364.html 在阅读Java代码的時候 我们时会看到Class.this的使 ...

  9. MongoDB 3.x 安装配置

    目录 (见右侧目录栏导航)- 1. 安装Mongodb    - 1.1 使用二进制包安装    - 1.2 运行MongoDB- 2. MongoDB 配置文件详解    - 2.1 说明    - ...

  10. word2vec原理

    最原始的是NNLM,然后对其改进,有了后面的层次softmax和skip gram 层次softmax:去掉了隐藏层,后面加了huffuman树,concat的映射层也变成了sum skip gram ...