题目链接:

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

node *head=(node*)malloc(sizeof(node));
for(int i=0; i<26; i++)
{
head->next[i] = NULL;
head->sum = 0;
}
可以改成node *head=new node();
要用c++提交才对,不然G++就内存超限了-_-
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
using namespace std; struct node
{
int sum;
node *next[];
}; void BuildLibTree(node *head, char s[])
{
node *p = head,*q; for(int i=; s[i]; i++)
{
int k = s[i] - 'a';
if(p->next[k] == NULL)
{
q=(node*)malloc(sizeof(node));
for(int j=; j<; j++)
{
q->next[j] = NULL;
q->sum = ;
}
p->next[k] = q;
}
p = p->next[k];
p->sum++;
}
}
int Query(node *head, char s[])
{
node *p = head;
for(int i=; s[i]; i++)
{
int k = s[i]-'a';
if(p->next[k] == NULL)
return ;
p = p->next[k];
}
return p->sum;
}
int main()
{
char s[];
node *head=(node*)malloc(sizeof(node));
for(int i=; i<; i++)
{
head->next[i] = NULL;
head->sum = ;
}
while(gets(s),s[])
BuildLibTree(head, s); while(scanf("%s",s)!=EOF)
printf("%d\n", Query(head, s));
return ;
}

统计难题---hdu1251字典树模板的更多相关文章

  1. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  2. HDU1251 统计难题 (字典树模板)题解

    思路:模板题,贴个模板 代码: #include<cstdio> #include<cstring> #include<cstdlib> #include<q ...

  3. HDU 1251 统计难题 (字典树)(查询是否为前缀)

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

  4. HDU 1251 统计难题(字典树入门模板题 很重要)

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  6. HDU 1251 统计难题 (Trie树模板题)

    题目链接:点击打开链接 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单 ...

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

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

  8. [ACM] hdu 1251 统计难题 (字典树)

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

  9. HDU 1251 统计难题(字典树 裸题 链表做法)

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

随机推荐

  1. iOS开发-NSDictionary

    判断一个字典中是否存在某个key,有两种方法: 方法一: if ([dictionary allKeys] containsObject: key]){ // cotains key operatio ...

  2. java serialize 浅谈

    对象的串行化(Serialization) 一.串行化的概念和目的 1.什么是串行化 对象的寿命通常随着生成该对象的程序的终止而终止.有时候,可能需要将对象的状态保存下来,在需要时再将对象恢复.我们把 ...

  3. FFMPEG转换WAV到MP3

    下载FFMPEG https://ffmpeg.zeranoe.com/builds/ Example to encode VBR MP3 audio with ffmpeg using the li ...

  4. 查看linux系统类型、版本、位数

    如何查看LINUX操作系统是多少位的 方法1: 查看linux是不是64位的命令! file /sbin/init 结果会出来 xx bit 方法二: # getconf LONG_BIT32getc ...

  5. 游戏服务器学习笔记 5———— twisted Perspective Broker 透明代理

    实际上这章压根不需要我来说,twisted官网的Doc里面有专门介绍的章节.写的非常详细. http://twistedmatrix.com/documents/current/core/howto/ ...

  6. 【Spring Boot && Spring Cloud系列】那些Spring Boot中踩过的坑

    一.不连接数据库启动springboot报错 Cannot determine embedded database driver class for database type NONE 原因:Spr ...

  7. Android studio 运行demo时一直卡在"Installing APKS"时的解决办法

    现象 一 File --- Settings 二 看图操作

  8. Storm启动流程分析

    1. 客户端运行storm nimbus时,会调用storm的python脚本,该脚本中为每个命令编写一个方法,每个方法都可以生成一条相应的java命令. 命令格式如下:java -server xx ...

  9. 题目1447:最短路(Floyd算法)

    题目链接:http://ac.jobdu.com/problem.php?pid=1447 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  10. async 与await

    一. async 与await (https://segmentfault.com/a/1190000007535316) 1.async 是“异步”的简写,而 await 可以认为是 async w ...