zoukankan      html  css  js  c++  java
  • POJ 1056

    #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[2*MAXN+1];
    
    node * insert(node * root,string s,int index,int len)
    {
        if(s[index] == '0')
        {
            if(root->l == NULL)
            {
                root->l = &res[_index ++];
                root->l->boo = false;
                root->l->l = root->l->r = NULL;
                if(index == len-1)
                {
                    root->l->boo = true;
                    return root;
                }
            }
            else
            {
                if(index == len-1)
                {
                    ans = false;
                    return root;
                }
                if(root->l->boo == true)
                {
                    ans = false;
                    return root;
                }
            }
    
    
            root->l = insert(root->l,s,index+1,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-1)
                {
                    root->r->boo = true;
                    return root;
                }
            }
            else
            {
                if(index == len-1)
                {
                    ans = false;
                    return root;
                }
                if(root->r->boo == true)
                {
                    ans = false;
                    return root;
                }
            }
            root->r = insert(root->r,s,index+1,len);
            return root;
        }
    }
    
    int main()
    {
        //freopen("acm.acm","r",stdin);
        string s;
        int time = 0;
        while(cin>>s)
        {
            _index = 0;
            ans = true;
            node * root = &res[_index ++];
            root->boo = false;
            root->l = root->r = NULL;
            if(ans)
            {
                root = insert(root,s,0,s.length());
            }
            while(cin>>s)
            {
                if(s == "9")
                {
                    break;
                }
                if(ans)
                {
                    root = insert(root,s,0,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

  • 相关阅读:
    jmeter接口测试二
    jmeter 插件入口
    Python正则匹配中的最小匹配和贪婪匹配
    python中的url编码和解码(encode与decode)乱码
    python2.7+pyqt+eric基本控件操作(制作界面化程序)
    python2.7+PyQt4+eric6 界面开发环境配置
    centos配置静态ip地址
    分片,步长,索引
    我看过的几本书籍
    软件测试工程师的成长之路(个人看法)
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563240.html
Copyright © 2011-2022 走看看