Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

唉????我没排序咋过的?????数据水的一匹

Posted by tjrac6016203284 at 2018-05-23 20:07:26 on Problem 1056
In Reply To:注意排序。 Posted by:sunl449554866 at 2014-08-28 22:03:20
#include<iostream>
#include<cstdio>
using namespace std;

struct node
{
    int num;
    node *son[2];
    node()
    {
        num=-1;
        son[0]=NULL;
        son[1]=NULL;
    }
};

int flag=1;
void Insert(node *&p,char temp[],int i)
{
    if(temp[i]=='\0')
    {
        if(p==NULL)
            p=new node;
        p->num=1;
    }
    else
    {
        if(p==NULL)
            p=new node;
        int tc=temp[i]-'0';
        if(p->num==1)
            flag=0;
        else
            Insert(p->son[tc],temp,i+1);

    }
}

int main()
{
    char temp[20];
    node *root;
    root=NULL;
    int ctor=1;
    while(~scanf("%s",temp))
    {
        if(temp[0]=='9')
        {

            if(flag)
                printf("Set %d is immediately decodable\n",ctor++);
            else
                printf("Set %d is not immediately decodable\n",ctor++);

            flag=1;
            root=NULL;
        }
        else
        {
            if(flag)
            Insert(root,temp,0);
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator