hdu1251统计难题(字典树模版)
来源:互联网 发布:最流行编程语言 编辑:程序博客网 时间:2024/05/16 05:23
http://acm.hdu.edu.cn/showproblem.php?pid=1251
#include<iostream>#include<string>#include<cstdio>using namespace std;struct Tire{ int num;//相同前缀的字符串个数 Tire *next[26];//26个字母}Node;Tire *head;//头结点void Insert(string s)//插入字典树{ Tire *T=head,*t; int i,j; for(i=0;i<s.size();i++) { int id=s[i]-'a'; if(T->next[id]==NULL) { t=new Tire; for(j=0;j<26;j++) { t->next[j]=NULL; } t->num=0; T->next[id]=t; } T=T->next[id]; T->num++; }}int Find(string s)//搜索相同前缀的字符串个数{ Tire *T=head; int count,i; for(i=0;i<s.size();i++) { int id=s[i]-'a'; if(T->next[id]==NULL) { count=0; break; } else { T=T->next[id]; count=T->num; } } return count;}int main(){ char s[15]; int i; head=new Tire; for(i=0;i<26;i++) { head->next[i]=NULL; head->num=0; } while(gets(s),strcmp(s,"")) { Insert(s); } while(gets(s)) { cout<<Find(s)<<endl; } return 0;}
0 0
- hdu1251统计难题(字典树模版)
- hdu1251 统计难题(字典树)
- hdu1251统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251 统计难题(字典树)
- HDU1251 统计难题(字典树模板)
- HDU1251统计难题(字典树模板)
- HDU1251 统计难题(字典树)
- 统计难题(hdu1251,字典树)
- hdu1251 统计难题 (字典树查找)
- hdu1251统计难题(字典树)
- hdu1251 统计难题(字典树)
- hdu1251 统计难题(字典树)
- HDU1251-统计难题(字典树)
- hdu1251 统计难题 字典树
- 【字典树】 hdu1251 统计难题
- hdu1251 统计难题(字典树)
- 统计难题(hdu1251字典树)
- POJ 2922 Honeymoon Hike(DFS/BFS+二分+枚举区间)
- OpenGL编程低级错误
- "无头单链表中删除节点"有感——变通 2014-03-18 17:56
- Java解析XML文档
- 用uboot 烧写uboot linux内核 文件系统到nandflash的 过程以及bootm go命令启动与区别
- hdu1251统计难题(字典树模版)
- Java 7之基础 - 强引用、弱引用、软引用、虚引用
- 关于集合视图UICollectionView
- Linux内核实现的双向链表(1)
- 基于 Apache 在本地配置多个虚拟主机
- 直接读取相册照片
- 使用jQuery自动跳转
- 【剑指offer】两个链表的第一个公共结点
- 字符设备驱动 架构分析