zoukankan      html  css  js  c++  java
  • poj1056

    简单题

    #include <iostream>
    #include <string>
    using namespace std;
    
    struct cnode
    {
        cnode    *pzero, *pone;
        bool    end;
    }trie[20000];
    
    int        ncount, t;
    
    bool insert(cnode *proot, char *a)
    {
        if (proot->end)
            return false;
        if (a[0] == '1')
        {
            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 + 1);
            }
            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 + 1);
        }
        proot->end = true;
        if (proot->pone == NULL && proot->pzero == NULL)
            return true;
        return false;
    }
    
    void init()
    {
        char*    st;
        bool    ans;
    
        st = "";
        ncount = 0;
        trie[0].end = false;
        trie[0].pzero = NULL;
        trie[0].pone = NULL;
        ans = true;
        while (true)
        {
            st = new char[11];
            if (!(cin >> st))
                exit(0);
            if (st[0] == '9')
                break;
            if (ans)
                if (!insert(trie, st))
                    ans = false;
            getchar();
        }
        printf("Set %d is ", t);
        if (ans)
            printf("immediately decodable
    ");
        else
            printf("not immediately decodable
    ");
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        t = 0;
        while (true)
        {
            t++;
            init();
        }
        return 0;
    }
    View Code
  • 相关阅读:
    SQL Server 调优系列进阶篇
    封装 RabbitMQ.NET
    RabbitMQ 的行为艺术
    SQL Server 调优系列进阶篇
    SQL Server 调优系列进阶篇
    FastFrameWork 快速开发框架
    SQL Server 调优系列进阶篇
    Java基础:三目运算符
    marquee标签,好神奇啊...
    Java JFrame 和 Frame 的区别
  • 原文地址:https://www.cnblogs.com/rainydays/p/3171683.html
Copyright © 2011-2022 走看看