hdu1671
来源:互联网 发布:做淘宝客怎么拉人 编辑:程序博客网 时间:2024/05/02 04:41
/*
分析:
昨天才自学了字典树,晚上还在想这种数据结构的推广,想到的就有
数字的,没想到今儿就碰上了,轻松搞定~O(∩_∩)O~
建立字典树,每次测试完要释放。
2012-07-05
*/
分析:
昨天才自学了字典树,晚上还在想这种数据结构的推广,想到的就有
数字的,没想到今儿就碰上了,轻松搞定~O(∩_∩)O~
建立字典树,每次测试完要释放。
2012-07-05
*/
#include"stdio.h"#include"string.h"#include"stdlib.h"struct dic{struct dic *child[10];};struct dic *root;void insert(char *source){struct dic *now,*newnode;int i,j;int len;len=strlen(source);now=root;for(i=0;i<len;i++){if(now->child[source[i]-'0'])now=now->child[source[i]-'0'];else{newnode=(struct dic *)malloc(sizeof(struct dic));for(j=0;j<10;j++)newnode->child[j]=0;now->child[source[i]-'0']=newnode;now=newnode;}}}int find(char *source){struct dic *now;int i;int len;int flag;len=strlen(source);now=root;for(i=0;i<len;i++)now=now->child[source[i]-'0'];flag=0;for(i=0;i<10;i++)if(now->child[i]){flag=1;break;}return flag;}void release(struct dic * now){int i;for(i=0;i<10;i++)if(now->child[i])release(now->child[i]);free(now);}int main(){int T;int n;int i,l,j;int ans;char str[10011][12];char temp[12];scanf("%d",&T);while(T--){root=(struct dic *)malloc(sizeof(struct dic));for(j=0;j<10;j++)root->child[j]=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%s",str[i]);insert(str[i]);}ans=0;for(i=0;i<n;i++){ans=find(str[i]);if(ans)break;}if(ans)printf("NO\n");elseprintf("YES\n");release(root);}return 0;}
- hdu1671
- hdu1671
- hdu1671
- hdu1671
- hdu1671
- HDU1671
- hdu1671
- hdu1671
- HDU1671字典树
- hdu1671 Phone List
- hdu1671 Phone List
- Phone List hdu1671
- HDU1671-Phone List
- HDU1671 Phone List
- hdu1671之字典树
- hdu1671 Phone List
- hdu1671( 字典树)
- hdu1671 字典树 入门
- MVC详解:了解真正所谓的"框架"
- 关联、聚合、合成与依赖
- ASP.NET用MyXls实现Excel数据导出
- Excel高级检索--通配符
- 敏捷开发-介绍
- hdu1671
- 多用户分权限操作同一工作表(转帖+亲自实践)
- Servlet中的各种问题 乱码
- CVS 常用命令
- 纠结啊
- 我理想中的手机
- 双击回退键退出应用
- 可变参数, 它依赖于堆栈----小话c语言(23)
- Linux下实现反转一个字符串或者数组中的数据