博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1251 统计难题 (字典树入门题)
阅读量:4519 次
发布时间:2019-06-08

本文共 1352 字,大约阅读时间需要 4 分钟。

1 /******************************************************* 2 题目:  统计难题 (hdu 1251) 3 链接:   http://acm.hdu.edu.cn/showproblem.php?pid=1251 4 算法:  字典树 5 提示:   这题压要用c++提交,G++会超内存 6 *******************************************************/ 7 #include
8 #include
9 #include
10 #include
11 using namespace std;12 char s[11];13 typedef struct Node 14 {15 Node *next[26];16 int cut;17 }Node;18 Node *root;19 void inser(char *s)20 {21 Node *p=root;22 for (int i=0;s[i];i++)23 {24 int x=s[i]-'a';25 if (p->next[x]==NULL)26 {27 p->next[x]=(Node *)malloc(sizeof(Node));28 p->next[x]->cut=0;29 for (int i=0;i<26;i++) p->next[x]->next[i]=NULL;30 }31 p=p->next[x];32 p->cut++;33 }34 }35 int Find(char *s)36 {37 Node *p=root;38 for (int i=0;s[i];i++)39 {40 int x=s[i]-'a';41 if (p->next[x]==NULL) return 0;42 p=p->next[x];43 }44 return p->cut;45 }46 int main()47 {48 root=new Node();49 while (gets(s))50 {51 if (strcmp(s,"")==0) break;52 else inser(s);53 }54 while (gets(s))55 {56 printf("%d\n",Find(s));57 }58 return 0;59 }

 

转载于:https://www.cnblogs.com/pblr/p/5768729.html

你可能感兴趣的文章
C# : 操作Word文件的API - (将C# source中的xml注释转换成word文档)
查看>>
C#中字符串转换成枚举类型的方法
查看>>
psplash
查看>>
git的安装和简单使用
查看>>
20151024-1025-威海-第5届全国高校软件工程专业教育年会参会总结
查看>>
Airplace平台
查看>>
TinyOS实例介绍
查看>>
15个nosql数据库
查看>>
css hack 尽我所见
查看>>
[转]ORACLE联机日志文件无故全部消失
查看>>
Javascript基础学习12问(四)
查看>>
[原]VS2012入门图文教程——第一个程序Hello World
查看>>
#pragma once 与 #ifndef 解析(转载)
查看>>
swift 数据存储
查看>>
Objective-C内存管理教程和原理剖析(三)
查看>>
最大子数组
查看>>
pyton random 模块
查看>>
.bat以管理员身份运行
查看>>
如何用3升和5升桶量取4升水?
查看>>
部署kubernetes1.8.3高可用集群
查看>>