hdu1251
来源:互联网 发布:单片机原理及应用 编辑:程序博客网 时间:2024/06/05 22:55
题意就不用说辣,就是套用字典树的模板
#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>using namespace std;#define read freopen("q.in","r",stdin)#define maxn 10002struct dictree{int n;struct dictree *child[26]; };dictree *root;void init(){root=(struct dictree *)malloc(sizeof(struct dictree));memset(root->child,0,sizeof(root->child));} void insert(char *s){struct dictree *cur,*newn;cur=root;for(;*s;s++){if(cur->child[*s-'a']!=0){cur=cur->child[*s-'a'];cur->n+=1;}else {newn=(struct dictree*)malloc(sizeof(struct dictree));memset(newn->child,0,sizeof(newn->child));cur->child[*s-'a']=newn;cur=newn;cur->n=1;}}}int find(char *s){struct dictree *cur,*newn;cur=root;for(;*s;s++){if(cur->child[*s-'a']!=0) cur=cur->child[*s-'a'];else return 0;}return cur->n; }int main(){char s[11];int i;init();while(gets(s) && s[0]!='\0')insert(s);while(gets(s))cout<<find(s)<<endl; }
参考资料:
杭电PPT:
http://wenku.baidu.com/link?url=YK4ZfzBnLhaJMjXHdPO9icCZP-A0alo8YCRsrenUwisJkuUH9-KJDn1KmFYNO3ZyEZ_EYFillhQc5bXp9_rupyLog8YUkJiOe6NJvN507ma
0 0
- hdu1251
- HDU1251
- hdu1251
- hdu1251
- hdu1251
- hdu1251
- hdu1251
- hdu1251
- hdu1251
- HDU1251
- hdu1251
- hdu1251
- HDU1251.cpp
- hdu1251 字符统计
- 统计难题 hdu1251
- HDU1251字典树
- hdu1251 字典树
- HDU1251统计难题
- 游戏引擎不仅是代码,更多的是完善的工具
- 判断字符串中的字符是否唯一
- 如何查看VS2010中VC++目录中的环境变量
- C#实现窗体拖动时各个控件同比自动放缩大小
- CodeForces 341D
- hdu1251
- Spring - 集成多数据源于MyBatis
- Android 开发测试环境切换工具
- 软件架构的5视图法
- 黑马视频学习笔记-内存管理-set方法内存管理
- 理解 JMeter 聚合报告(Aggregate Report)
- Shell 字符串处理、获取文件名和后缀名
- ubuntu下编译时出现“make: arm-linux-gcc:命令未找到”的问题
- Recordset对象