HDU 1251 字典树
来源:互联网 发布:linux 同时连接内外网 编辑:程序博客网 时间:2024/05/16 08:04
字典树 重点在建树的过程
#include<stdio.h>#include<string.h>#include<stdlib.h>struct dictree{ struct dictree*child[26]; int n;};struct dictree *root;void insert(char *source){ int len,i,j; struct dictree *cur,*newnode; len=strlen(source); if(len==0) return ; cur=root; for(i=0;i<len;i++) { if(cur->child[source[i]-'a']!=0) { cur=cur->child[source[i]-'a']; cur->n=cur->n+1; } else { newnode=(struct dictree *)malloc(sizeof(struct dictree)); for(j=0;j<26;j++) newnode->child[j]=0; cur->child[source[i]-'a']=newnode; cur=newnode; cur->n=1; } }}int find(char *source){ int i,len; struct dictree *cur; len=strlen(source); if(len==0) return 0; cur=root; for(i=0;i<len;i++) { if(cur->child[source[i]-'a']!=0) cur=cur->child[source[i]-'a']; else return 0; } return cur->n;}int main(){ char tmp[11]; int i,j; root=(struct dictree *)malloc(sizeof(struct dictree)); for(i=0;i<26;i++) root->child[i]=0; while(gets(tmp)&&strlen(tmp)!=0) insert(tmp); while(scanf("%s",tmp)!=EOF) { i=find(tmp); printf("%d\n",i); } return 0;}
- hdu 1251(字典树)
- hdu 1251 字典树
- HDU 1251 字典树
- hdu 1251 字典树
- hdu 1251 字典树
- HDU-1251,字典树
- HDU 1251 字典树
- 1251 hdu 字典树
- HDU 1251(字典树)
- HDU 1251 字典树
- HDU 1251(字典树)
- HDU 1251 字典树
- hdu 1251 字典树
- HDU 1251 字典树
- 字典树 hdu 1251
- hdu 1251 字典树
- HDU 1251 字典树
- hdu 1251 字典树
- xps 13 ubuntu记录
- 快速排序的应用
- HTML5会取代App应用吗?
- c++ new的用法
- poj2451 半平面交
- HDU 1251 字典树
- 安装后新建Android出现“AndroidManifest.xml 系统找不到指定的文件”解决方案
- 在vs2010的输出窗口显示编译时间
- HDU 3879 Base Station 最大权闭合图
- JQuery选择器
- 有一天这些都会过去的
- MyEclipse 8.5安装CDT插件和NetBeans安装C++开发环境
- 数据挖掘中的决策树技术
- SQL server--数据安全