POJ -- 1056 IMMEDIATE DECODABILITY (Trie 树)
2015-06-20 16:22
453 查看
题目大意:
判断在一组字符串中,是否有一个字符串是另一个字符串的前缀;
代码实现:
判断在一组字符串中,是否有一个字符串是另一个字符串的前缀;
代码实现:
#include<cstdio> #include<cstring> #include<iostream> #include<cstdlib> using namespace std; char code[15]; bool flag; struct tree{ int flag; tree *next[2]; }*root; tree *Create(){ tree *p; p=(tree *)malloc(sizeof(tree)); p->flag=0; for(int i=0;i<2;++i) p->next[i]=NULL; return p; } void Insert(char *code){ tree *p=root; int i=0,x,l=strlen(code); while(i<l){ x=code[i++]-'0'; if((p->next[x])==NULL) p->next[x]=Create(); else if(i==l) flag=1; p=p->next[x]; if(p->flag==1) flag=1; } p->flag=1; } int main(){ int cnt=0; root=Create(); while(~scanf("%s",code)){ if(code[0]=='9'){ if(!flag) printf("Set %d is immediately decodable\n",++cnt); else printf("Set %d is not immediately decodable\n",++cnt); root=Create(); flag=0; }else Insert(code); } }
相关文章推荐
- Redis学习手册(Key操作命令)
- 人才招聘网站
- Hadoop集群(第8期)_HDFS初探之旅
- 《Material Design》设计 - 色彩篇 - UI调色板
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第九课: Cocos2D-X引擎框架4
- PHP数组与对象之间用递归转换
- asp.net <%%>&<%#%>&<%=%>&<%@%>&<%$%>用法区别
- 拓扑排序
- Hadoop集群(第7期)_Eclipse开发环境设置
- UVA434 - Matty's Blocks
- Deutsch lernen (05)
- LeetCode之“散列表”:Valid Sudoku
- UVa 11346 Probability
- JavaWeb学习笔记——Tomcat配置
- Pascal's Triangle II
- hdu 2112 map+Dijkstra
- poj -- 2001 Shortest Prefixes (Trie 树)
- Hadoop集群(第6期)_WordCount运行详解
- Android ListView 单条刷新方法实践及原理解析
- bzoj3672