/**
[字典树 ]hdu 1251 统计难题
统计前缀出现次数
*/
#include <stdio.h>
#include <string.h>
#define N 1000000
struct tireTree
{
int cnt;
tireTree *child[26];
}tt[N],*spt;
void insert(char *s,tireTree *&rt)
{
tireTree *loc;
if(rt == NULL)
rt = spt++;
loc = rt;
int num;
for(int i = 0; s[i]; ++i)
{
num = s[i] - 'a';
if(loc->child[num] == NULL)
loc->child[num] = spt++;
loc = loc->child[num];
loc->cnt++;
}
}
int query(char *s,tireTree *rt)
{
tireTree *loc = rt;
if(rt == NULL)
return 0;
int num;
for(int i = 0; s[i]; ++i)
{
num = s[i] - 'a';
if(loc->child[num] == NULL)
return 0;
loc = loc->child[nu
[字典树 ]hdu 1251 统计难题
最新推荐文章于 2021-11-09 00:20:03 发布
该博客介绍了一个使用字典树(Trie Tree)解决HDU 1251统计难题的C语言实现。主要包含两个功能:插入字符串到字典树中并更新计数,以及查询字符串在字典树中出现的次数。通过插入和查询操作,实现了对前缀字符串出现次数的统计。
订阅专栏 解锁全文
1004

被折叠的 条评论
为什么被折叠?



