ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1136. Parliament

WHY I GOT CE?? HeLp!!
Posted by milkkung55 22 Mar 2005 13:00
THIS IS MY CODE

#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
  int val;
  struct node *l,*r;
}NODE;

void entree(NODE* p,int a)
{
  if(a<p->val)
  {
    if(p->l==NULL)
    {
      p->l=(NODE*)malloc(sizeof(NODE));
      p=p->l;
      p->val=a;
      p->l=p->r=NULL;
    }
    else
      entree(p->l,a);
  }
  else
  {
    if(p->r==NULL)
    {
      p->r=(NODE*)malloc(sizeof(NODE));
      p=p->r;
      p->val=a;
      p->l=p->r=NULL;
    }
    else
      entree(p->r,a);
  }
}
void order(NODE *p)
{
   if(p->r!=NULL) order(p->r);
   if(p->l!=NULL) order(p->l);
   printf("%d ",p->val);
}

void main()
{
  NODE *first,*cur;
  int *ar,n;
  scanf("%d",&n);
  ar=(int *)malloc(sizeof(int)*n);
  for(int i=n-1;i>=0;i--)
    scanf("%d",ar+i);
  first=(NODE*)malloc(sizeof(NODE));
  first->val=*ar;
  first->l=first->r=NULL;
  for(i=1;i<n;i++)
  {
    cur=first;
    entree(cur,*(ar+i));
  }
  cur=first;
  order(cur);
}

ThAnKs FoR AdVaNcE
Re: WHY I GOT CE?? HeLp!!
Posted by Cybernetics Team 22 Mar 2005 13:57
Declare your i variable in the main function along with the other ints (*ar, n), not in the for, and you'll get AC. I don't know why this happens cause in my Visual C++ it works like that... Also you cand take a look at the errors by choosing send result to mail, as I've done with your source now...
Re: WHY I GOT CE?? HeLp!!
Posted by milkkung55 22 Mar 2005 15:42
Thank YOUUU!! Very much ^o^
Re: WHY I GOT CE?? HeLp!!
Posted by Someone 9 Jan 2006 21:19
I think the problem was in the second loop "for": variable "i" was not declared...
//----------------------------
  for(i=1;i<n;i++)
  {
    cur=first;
    entree(cur,*(ar+i));
  }
//----------------------------