裸的字典树还是挺简单的、

四个基本操作建立、查找、插入、删除

建立新结点我是用的c++中 new操作、当然也可以用malloc,都方便

不过指针阿、地址阿、这其中关系什么的我貌似还不是很清楚阿、

因为刚开始我的头结点也是定义的指针、然后程序就炸了、我不清楚原因呢、

有待弄清楚、

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
typedef struct node
{
int cnt;
struct node *next[];
node()
{
cnt=;
memset(next,,sizeof(next));
}
}t;
node root; //头结点
void save(char *s)
{
int len=strlen(s);
if(len==) return;
node *p=&root;
node *tmp=NULL;
for(int i=;i<len;++i){
if(p->next[s[i]-'a']==NULL){
tmp=new struct node;
p->next[s[i]-'a']=tmp;
}
p=p->next[s[i]-'a'];
p->cnt++;
}
}
void findtree(char *s)
{
struct node *p=&root;
int i,l=strlen(s);
for(int i=;i<l;++i){
if(p->next[s[i]-'a']==NULL){
printf("0\n");
return;
}
p=p->next[s[i]-'a'];
}
printf("%d\n",p->cnt);
return;
}
int main()
{
char s[];
while(gets(s)&&s[]!=) save(s);
while(~scanf("%s",s))
findtree(s);
return ;
}

HDU 1251 裸的字典树、入门题的更多相关文章

  1. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

  2. hdu 1251 统计难题 字典树第一题。

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

  3. HDU 1251 统计难题 字典树大水题

    今天刚看的字典树, 就RE了一发, 字典树原理还是很简单的, 唯一的问题就是不知道一维够不够用, 就开的贼大, 这真的是容易MLE的东西啊, 赶紧去学优化吧. HDU-1251 统计难题 这道题唯一的 ...

  4. hdu -1251 统计难题(字典树水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 建树之后 查询即可. G++提交 ME不知道为什么,c++就对了. #include <iostre ...

  5. HDU 4825 Xor Sum(01字典树入门题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4825 题意: 给出一些数,然后给出多个询问,每个询问要从之前给出的数中选择异或起来后值最大的数. 思路:将给出的 ...

  6. HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)

    Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...

  7. hdu 1251 统计难题(字典树)

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

  8. HDU 1251统计难题 字典树

    字典树的应用. 数据结构第一次课的作业竟然就需要用到树了!!!这不科学啊.赶紧来熟悉一下字典树. 空间开销太大T T #include<cstdio> #include<cstrin ...

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

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

随机推荐

  1. Ubuntu下安装go语言

    参考:http://golang.org/doc/install/source 1. 下载go源代码 sudo apt-get install mercurial hg clone -u releas ...

  2. Sql基本知识回顾

    一. SQL 基本语句 SQL 分类: DDL —数据定义语言 (Create , Alter , Drop , DECLARE) DML —数据操纵语言 (Select , Delete , Upd ...

  3. etcd使用

    下载: https://github.com/etcd-io/etcd/releases/tag/v3.3.13 tar -zxvf   etcd-v3.3.13-linux-amd64.tar.gz ...

  4. PSPP:顶替SPSS常用功能的优秀软件, Linux 下的经济学用软件

    几个替代SPSS的软体Salstat http://salstat.sourceforge.net/PSPP http://www.gnu.org/software/pspp/pspp.htmlR h ...

  5. Directx11教程(8) 一个新的camera类

    原文:Directx11教程(8) 一个新的camera类      本章我们将替换掉CameraClass类,实现一个稍微靠谱点的摄像机类.并通过Q,W,E,A,S,D,Z,X,C等按键实现摄像机的 ...

  6. Python中if __name__ == '__main__':理解

    在很多python脚本中在最后的部分会执行一个判断语句if __name__ == "__main__:",之后还可能会有一些执行语句.那添加这个判断的目的何在? 在python编 ...

  7. shell学习(23)- diff和patch

    diff命令可以生成两个文件之间的差异对比. (1) 先创建下列用于演示的文件.文件 1:version1.txt this is the original text line2 line3 line ...

  8. NEFU 118 n!后面有多少个0【数论】

    http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=118 求n!后面有多少个0(1<=n<=1000000000) ...

  9. 利用IDEA构建springboot应用-配置文件

    application.properties配置文件(不建议采用这种配置) 配置文件采用:application.yml文件会更简便,要带空格 属性配置与类中取值 添加bean属性配置到一个类里面,采 ...

  10. Python基础:09函数式编程

    Python支持一些函数式编程的特性.比如lambda. map().reduce().filter()函数. 一:匿名函数与lambda Python可以用lambda 关键字创造匿名函数.匿名函数 ...