#include <iostream>
#include <string>
#define MAXN 50
using namespace std; struct node
{
node * l;
node * r;
bool boo;
node()
{
l = NULL;
r = NULL;
boo = false;
}
}; bool ans; int _index; node res[*MAXN+]; node * insert(node * root,string s,int index,int len)
{
if(s[index] == '')
{
if(root->l == NULL)
{
root->l = &res[_index ++];
root->l->boo = false;
root->l->l = root->l->r = NULL;
if(index == len-)
{
root->l->boo = true;
return root;
}
}
else
{
if(index == len-)
{
ans = false;
return root;
}
if(root->l->boo == true)
{
ans = false;
return root;
}
} root->l = insert(root->l,s,index+,len);
return root;
}
else
{
if(root->r == NULL)
{
root->r = &res[_index ++];
root->r->boo = false;
root->r->l = root->r->r = NULL;
if(index == len-)
{
root->r->boo = true;
return root;
}
}
else
{
if(index == len-)
{
ans = false;
return root;
}
if(root->r->boo == true)
{
ans = false;
return root;
}
}
root->r = insert(root->r,s,index+,len);
return root;
}
} int main()
{
//freopen("acm.acm","r",stdin);
string s;
int time = ;
while(cin>>s)
{
_index = ;
ans = true;
node * root = &res[_index ++];
root->boo = false;
root->l = root->r = NULL;
if(ans)
{
root = insert(root,s,,s.length());
}
while(cin>>s)
{
if(s == "")
{
break;
}
if(ans)
{
root = insert(root,s,,s.length());
}
}
cout<<"Set "<<++ time;
if(ans == false)
{
cout<<" is not immediately decodable"<<endl;
}
else
{
cout<<" is immediately decodable"<<endl;
}
}
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 1056的更多相关文章

  1. poj 1056 IMMEDIATE DECODABILITY(KMP)

    题目链接:http://poj.org/problem?id=1056 思路分析:检测某字符串是否为另一字符串的前缀,数据很弱,可以使用暴力解法.这里为了练习KMP算法使用了KMP算法. 代码如下: ...

  2. poj 1056 IMMEDIATE DECODABILITY 字典树

    题目链接:http://poj.org/problem?id=1056 思路: 字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变 ...

  3. POJ 1056 IMMEDIATE DECODABILITY 【Trie树】

    <题目链接> 题目大意:给你几段只包含0,1的序列,判断这几段序列中,是否存在至少一段序列是另一段序列的前缀. 解题分析: Trie树水题,只需要在每次插入字符串,并且在Trie树上创建节 ...

  4. POJ 1056 IMMEDIATE DECODABILITY

    IMMEDIATE DECODABILITY Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9630   Accepted: ...

  5. POJ 1056 IMMEDIATE DECODABILITY Trie 字符串前缀查找

    POJ1056 给定若干个字符串的集合 判断每个集合中是否有某个字符串是其他某个字符串的前缀 (哈夫曼编码有这个要求) 简单的过一遍Trie就可以了 #include<iostream> ...

  6. 字典树trie的学习与练习题

    博客详解: http://www.cnblogs.com/huangxincheng/archive/2012/11/25/2788268.html http://eriol.iteye.com/bl ...

  7. 蓝书2.3 Trie字典树

    T1 IMMEDIATE DECODABILITY poj 1056 题目大意: 一些数字串 求是否存在一个串是另一个串的前缀 思路: 对于所有串经过的点权+1 如果一个点的end被访问过或经过一个被 ...

  8. 【POJ】1056 IMMEDIATE DECODABILITY

    字典树水题. #include <cstdio> #include <cstring> #include <cstdlib> typedef struct Trie ...

  9. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

随机推荐

  1. input不能输入中文

    <input type="text" oninput="this.value = this.value.replace(/[\u4e00-\u9fa5d]/g, ' ...

  2. JavaScript 代码小片段

    1.获取对象 obj 的所有属性(自有属性和继承属性),保存到数组 lst 中 //获取对象obj的所有属性(自有属性和继承属性),保存到数组lst 中 var lst = []; function ...

  3. 2018.06.29 NOIP模拟 1807(简单递推)

    1807 题目背景 SOURCE:NOIP2015-SHY-2 题目描述 给出一个由数字('0'-'9')构成的字符串.我们说一个子序列是好的,如果他的每一位都是 1.8.0.7 ,并且这四个数字按照 ...

  4. hdu-1107(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1107 注意:1.路线是要反向的,走不通就反向: 2.输入输出全部是整形 3.攻击力不断变化 #incl ...

  5. IDEA如何初始化Git本地仓库,并提交到远程仓库

    本文转载自:http://blog.csdn.net/two_people/article/details/77008593 1. 首先在远程仓库上新建一个项目,码云和github都可以,我这里使用的 ...

  6. ( KMP 求循环节的个数)Power Strings -- poj -- 2406

    链接: http://poj.org/problem?id=2406 Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bi ...

  7. (并查集) Wireless Network --POJ --2236

    链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  8. POJ1511来回最短路

    POJ1511 问你从1到其它点得所有最短路之和  与  其他点到1得所有最短路之和 得总和 思路很明确就是两次最短路,翻转一次地图就好了 一开始就是两次spfa之间处理好数据得更新管理就好 vect ...

  9. underscore utility

    1._.noConflict:命名冲突处理方法 _.noConflict = function() { root._ = previousUnderscore; //返回this不错 return t ...

  10. D3 drag

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...