hdu1251 统计难题 数据结构之Trie树
来源:互联网 发布:安装python没有idle 编辑:程序博客网 时间:2024/05/22 05:11
哈哈,第一次用Trie树,从网上找了个模板改了改,然后自己写了search()。
题目很简单,就不解释了。
#include<stdio.h>#include <string.h>const int sonnum=26, base='a';struct Trie{int num; //记录有多少个单词能到达次,也即相同前缀的个位//bool terminal; //判断是否是结束节点struct Trie *son[sonnum];Trie(){num=1;// terminal=false;memset(son,NULL,sizeof(son));}};void Insert(Trie *root, char *s){Trie *temp=root;while(*s){if(temp->son[*s-base]==NULL) //不存在 则建立temp->son[*s-base]=new Trie();//NewTrie();else {temp->son[*s-base]->num++;}temp=temp->son[*s-base];s++;}//temp->terminal=true; //到达尾部,标记一个串}int search(Trie *root,char a[]){Trie *temp=root;int i=0;while(a[i]){if(temp->son[a[i]-base]!=NULL)temp=temp->son[a[i]-base];else return 0;i++;}return temp->num;}int main(){char a[11];Trie *root=new Trie();while(gets(a)){if(a[0]=='\0')break;Insert(root,a);}while(gets(a))printf("%d\n",search(root,a));return 0;}
- hdu1251 统计难题 数据结构之Trie树
- HDU1251 统计难题 【trie树】
- HDU1251统计难题 trie树
- HDU1251 统计难题(Trie树)
- hdu1251 统计难题 (Trie)
- hdu1251 统计难题 trie
- HDU1251(统计难题)---Trie树简单应用
- HDU1251 统计难题(Trie树)
- hdu1251 统计难题(Trie树入门题)
- hdu1251-> 统计难题(Trie树入门题)
- HDU1251 统计难题(trie树[重做])
- HDU1251 统计难题 【Trie 树入门】
- HDU1251 统计难题(Trie)
- HDU1251统计难题---Trie Tree
- [复习][HDU1251]字典树(trie树)统计难题
- 字典树 之 统计难题 hdu1251
- hdu1251 统计难题 字典树
- 【字典树】 hdu1251 统计难题
- Zend Studio使用
- android之MIME type
- 异常处理
- linux操作系统下c语言编程入门
- 《分数的加法运算编程——JAVA第三周》
- hdu1251 统计难题 数据结构之Trie树
- c++ static的作用,以及static对象在类和函数中区别
- Weblogic10 常用linux指令
- 重建二叉树
- JAVA中的"指针"
- 求前N个质数
- 使用java实现双向链表数据结构
- rand()和srand()
- archlinux批量添加用户