hdu_1251统计难题
来源:互联网 发布:雅思作文 知乎 编辑:程序博客网 时间:2024/05/20 06:50
#include<cstdio>#include<cstring>#include<malloc.h>typedef struct node{ int count; struct node *next[26];}*tree;void insert(tree h,char *s){ tree p=h; int len=strlen(s),i; for(i=0;i<len;i++) { int index=s[i]-'a'; if(p->next[index]!=NULL) { p=p->next[index]; p->count++; } else { tree tem=(tree)calloc(1,sizeof(node)); tem->count=1; p->next[index]=tem; p=tem; } }}int find(tree h,char *s){ tree p=h; int len=strlen(s),i; for(i=0;i<len;i++) { int index=s[i]-'a'; if(p->next[index]!=NULL) p=p->next[index]; else return 0; } return p->count;}void delet(tree head){ int i; for(i=0;i<26;i++) { if(head->next[i]!=NULL) delet(head->next[i]); } free(head);}int main(){ tree head=(tree)calloc(1,sizeof(node)); char s[11]; while(gets(s)&&s[0])//注意着要用gets,来读空行 { insert(head,s); } while(scanf("%s",s)!=EOF) { printf("%d\n",find(head,s)); } delet(head); return 0;}
0 0
- hdu_1251 统计难题
- hdu_1251统计难题
- 统计难题 (HDU_1251) 字典树
- hdu_1251 统计难题 trie模版
- hdu_1251 统计难题(字典树)
- HDU_1251 统计难题 【字典树||map】
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- 统计难题
- EasyUI DataGrid ToolBar 右对齐
- 图片排列
- #Otsu双阈值的二值化分割(opencv2实现)
- Android Activity和Intent机制学习笔记
- HDOJ Number Sequence(java)
- hdu_1251统计难题
- 贪心题集
- How To Programmatically Copy an IMG Element to the Clipboard
- ==与equals()的区别
- apache tomcat 6集群负载和session复制
- 多媒体编程——声音播放(1)
- OpenCV学习之五: 如何用指令启动或关闭OpenCV的CPU指令集CV_SSE2,CV_SSSE4等优化
- C++空类默认函数
- Android adb shell am/pm使用