简单题

#include <iostream>
#include <string>
using namespace std; struct cnode
{
cnode *pzero, *pone;
bool end;
}trie[]; int ncount, t; bool insert(cnode *proot, char *a)
{
if (proot->end)
return false;
if (a[] == '')
{
if (a[] != '\0')
{
if (proot->pone == NULL)
{
ncount++;
proot->pone = trie + ncount;
proot->pone->end = false;
proot->pone->pone = NULL;
proot->pone->pzero = NULL;
}
return insert(proot->pone, a + );
}
proot->end = true;
if (proot->pone == NULL && proot->pzero == NULL)
return true;
return false;
}
if (a[] != '\0')
{
if (proot->pzero == NULL)
{
ncount++;
proot->pzero = trie + ncount;
proot->pzero->end = false;
proot->pzero->pone = NULL;
proot->pzero->pzero = NULL;
}
return insert(proot->pzero, a + );
}
proot->end = true;
if (proot->pone == NULL && proot->pzero == NULL)
return true;
return false;
} void init()
{
char* st;
bool ans; st = "";
ncount = ;
trie[].end = false;
trie[].pzero = NULL;
trie[].pone = NULL;
ans = true;
while (true)
{
st = new char[];
if (!(cin >> st))
exit();
if (st[] == '')
break;
if (ans)
if (!insert(trie, st))
ans = false;
getchar();
}
printf("Set %d is ", t);
if (ans)
printf("immediately decodable\n");
else
printf("not immediately decodable\n");
} int main()
{
//freopen("t.txt", "r", stdin);
t = ;
while (true)
{
t++;
init();
}
return ;
}

poj1056的更多相关文章

  1. POJ1056 IMMEDIATE DECODABILITY & POJ3630 Phone List

    题目来源:http://poj.org/problem?id=1056   http://poj.org/problem?id=3630 两题非常类似,所以在这里一并做了. 1056题目大意: 如果一 ...

  2. poj1056(字符串判断是否存在一个字符串是另一个字符串的前缀)

    题目链接:https://vjudge.net/problem/POJ-1056 题意:给定一个字符串集,判断是否存在一个字符串是另一个字符串的前缀. 思路:和hdoj1671一样,有两种情况: 当前 ...

  3. poj1056 (Trie入门)寻找字符串前缀

    题意:给你一堆字符串,问是否满足对于任意两个字符串a.b,a不是b的前缀 字典树==前缀树==Trie树 trie入门题,只用到了insert和query操作 #include <cstdio& ...

  4. POJ1056 IMMEDIATE DECODABILITY【数据结构】

    题目地址:http://poj.org/problem?id=1056 Description An encoding of a set of symbols is said to be immedi ...

  5. POJ--1056 IMMEDIATE DECODABILITY && POJ--3630 Phone List(字典树)

    题目链接 题目大意 看输入的每个字符串中是否有一个字符串是另一个字符串的前缀 #include<iostream> #include<cstring> #include< ...

  6. ACM训练计划建议(写给本校acmer,欢迎围观和指正)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  7. 【POJ水题完成表】

    题目 完成情况 poj1000:A+B problem 完成 poj1002:电话上按键对应着数字.现在给n个电话,求排序.相同的归一类 完成 poj1003:求最小的n让1+1/2+1/3+...+ ...

  8. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

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

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

随机推荐

  1. POI往word模板中写入数据

    转: POI往word模板中写入数据 2018年03月24日 16:00:22 乄阿斗同學 阅读数:2977  版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...

  2. Python中__init__.py文件的作用详解

    转自http://www.jb51.net/article/92863.htm Python中__init__.py文件的作用详解 http://www.jb51.net/article/86580. ...

  3. lumen 单元测试的一些问题

    1.一个 test 多个请求 如 $this->post,然后又  $this->post,我们会发现第二个请求中的请求参数是和第一个请求的参数是完全一样的,然后在 Controller ...

  4. 交互式shell脚本对话框----whiptail指令

    当你在linux环境下setup软件的时候就会有相应的对话框让你输入.虽然我们已经习惯了这种交互的方法,但是如果有一种直观的界面来输入是不是会更加友好和方便呢,在shell脚本中你可以使用-whipt ...

  5. jQuery常用知识总结

    jQuery常用知识总结 简介 选择器 属性操作 jQuery() each event事件 jQuery扩展 一.简介 What is jQuery jQuery is fast small and ...

  6. Python 装饰器(进阶篇)

    装饰器是什么呢? 我们先来打一个比方,我写了一个python的插件,提供给用户使用,但是在使用的过程中我添加了一些功能,可是又不希望用户改变调用的方式,那么该怎么办呢? 这个时候就用到了装饰器.装饰器 ...

  7. __metaclass__ 实现单列模式

    class Singleton(type): """Singleton. @see: http://stackoverflow.com/questions/6760685 ...

  8. Java并发编程原理与实战三十五:并发容器ConcurrentLinkedQueue原理与使用

    一.简介 一个基于链接节点的无界线程安全队列.此队列按照 FIFO(先进先出)原则对元素进行排序.队列的头部 是队列中时间最长的元素.队列的尾部 是队列中时间最短的元素.新的元素插入到队列的尾部,队列 ...

  9. Java并发编程原理与实战二十一:线程通信wait&notify&join

    wait和notify wait和notify可以实现线程之间的通信,当一个线程执行不满足条件时可以调用wait方法将线程置为等待状态,当另一个线程执行到等待线程可以执行的条件时,调用notify可以 ...

  10. Web API: Security: Basic Authentication

    原文地址: http://msdn.microsoft.com/en-us/magazine/dn201748.aspx Custom HttpModule code: using System; u ...