字典树 hdu 1251
来源:互联网 发布:python iso8601 编辑:程序博客网 时间:2024/05/16 04:32
#include<stdio.h>#include<algorithm>#include<stdlib.h>#include<malloc.h>#include<string.h>#include<math.h>using namespace std;struct trie{ trie * next[26]; int bat=0;};int temp=0;int ani=0;int sum=0;trie * init(){ trie *tmp=new trie; for(int i=0;i<26;i++) { tmp->next[i]=NULL; } return tmp;}trie *H=init();void insert(char *s){ trie *tmp=H; int len=strlen(s); //printf("%d\n",len); for(int i=0;i<len;i++) { int k=s[i]-'a'; if(tmp->next[k]==NULL) { tmp->next[k]=init(); } tmp=tmp->next[k]; tmp->bat++; } //tmp->flag=true;}void out1(char *s){ trie *tmp=H; int len=strlen(s); for(int i=0;i<len;i++) { int k=s[i]-'a'; if(tmp->next[k]!=NULL) { tmp=tmp->next[k]; } else { ani=1; return ; } } int k=s[len-1]-'a'; if(tmp!=NULL) { //printf("%d\n",sum); sum=tmp->bat; //printf("%d\n",sum); } else ani=1; //puts("2"); //tt(tmp); return ;}void del(trie *tmp){ for(int i=0;i<26;i++) { if(tmp->next[i]!=NULL) del(tmp->next[i]); } free(tmp); return ;}int main(){ char s[10217]; while(gets(s)) { if(s[0]==0&&temp==0) { temp=1; continue; } if(s[0]==0&&temp==1) { temp=0; break; } if(temp==0) { insert(s); } else { out1(s); if(ani==1) { puts("0"); sum=0; ani=0; } else { if(sum==0) puts("1"); else printf("%d\n",sum); ani=0; sum=0; } } } return 0;}
0 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 字典树
- #笔记#圣思园 JavaWeb 第59讲——使用Firebug调试JS、JSUnit,XUnit
- 关于C语言中的预处理指令
- Objective-C NSNotificationCenter (通知)的使用方法
- Android 适配问题
- 从零开始搭建hadoop分布式集群环境:(五)hadoop完全分布式集群环境配置
- 字典树 hdu 1251
- python 安装pip
- Linux下高性能网络编程中的几个TCP/IP选项_SO_REUSEADDR、SO_RECVBUF、SO_SNDBUF、SO_KEEPALIVE、SO_LINGER、TCP_CORK、TCP_NODE
- Java中hashCode的作用
- iOS开发UI篇—UIScrollView控件介绍
- JS设计模式
- 2012年5月SAT香港真题解析
- 同步机制摘要
- 【Caffe】训练MNIST数据集模型