hdu1251 tire树入门
来源:互联网 发布:蒙古西征 知乎 编辑:程序博客网 时间:2024/06/08 11:12
#include<stdio.h>#include<string>#include<map>#include<vector>#include<cmath>#include<stdlib.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;const int N=1e4+10;const int MOD=1e9+7;int n,m,k;struct node{ node* child[26]; int cnt; node(){ cnt=0; for(int i=0;i<26;i++) child[i]=NULL; }};node *root=new node;node *p,*newp;void insert(char* s){ p=root; int c; int len=strlen(s)-1; for(int i=0;i<len;i++){ c=s[i]-'a'; if(p->child[c]!=NULL){ p=p->child[c]; p->cnt++; }else{ newp=new node; p->child[c]=newp; p=newp; p->cnt++; } }}int search(char *s){ int len=strlen(s); p=root; for(int i=0;i<len;i++){ int c=s[i]-'a'; if(p->child[c]==NULL) return 0; else p=p->child[c]; } return p->cnt;}int main(){#ifndef ONLINE_JUDGE freopen("aaa","r",stdin);#endif int T; char str[20]; while(fgets(str,100,stdin),strlen(str)!=1) insert(str); while(~scanf("%s",str)) printf("%d\n",search(str)); return 0;}
0 0
- hdu1251 tire树入门
- HDU1251 统计难题 tire树
- HDU1251(Trie树入门)
- hdu1251(字典树入门)
- HDU-1251(字典树<Tire>入门)
- hdu1251 统计难题(Trie树入门题)
- hdu1251-> 统计难题(Trie树入门题)
- HDU1251 统计难题 【Trie 树入门】
- tire树~!
- TIRE树
- Tire树
- tire树
- Tire树
- Tire树
- Tire树
- Tire树
- HDU1251 统计难题题解(字典树入门)
- 字典树(Tire树)
- Emacs 中的正则替换
- 统计学习笔记(2)——感知机模型
- CMD命令(添加删除管理员账户)
- Failed to read artifact descriptor for org.eclipse.tycho 错误
- Linux下查看文件和文件夹大小
- hdu1251 tire树入门
- %1$s %1$d Android string
- 如何快速学习使用mybatis以及总结
- 第一篇
- JAVA 面向对象( 类和对象)
- Activity之间传递List<T>数据
- swift和OC混合编程枚举类型无法判断
- 统计学习笔记(3)——k近邻法与kd树
- 杭电1596find the safest road(spfa)