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

Common Board

Question is: Does exist this file "<malloc.h>" at your server`s version?Or I have another problem?
Posted by Bushtruk Vyacheslav 27 Jan 2003 19:41
 Last night I`d finished,compiled,tested the 1053-Problem and after
sending I received four "Compilation Error"s, while at my computer
the program functioned normally.
 I use work with pointers and "<malloc.h>"-standart file,may be it`s
my problem.
I hope for truth...

Program`s cod by C++ Language.
#include <stdio.h>
#include <malloc.h>

typedef struct list{
    list*next;
    int inf;
} lst;
list *bl,*el;
int c=1;
void put(int i){
  list *p;
  p=(list*)malloc(sizeof(list));
  (*p).inf=i;
  if(c==1){ bl=p; el=p;}
  else{(*el).next=p; el=(*el).next; (*p).next=0;}
};
bool OOz(list *b,list *e){
  if(b==e){(printf("%d",(*b).inf));return true;}
  bool ans=false;
  bool c=false;
  list *p; p=b;
  while(p!=e){
    if((*p).inf!=0 && c==false){
      c=true;
      ans=true;
    }
    else
    if((*p).inf!=0 && c==true){
      ans=false;
      break;
    }
  p=(*p).next;
  }
  if((*p).inf!=0 && c==true)ans=false;
  return ans;
};

void main(){
  int q=0;
  scanf("%d",&q);
  for(int i=0,val;i<q;i++){
    scanf("%i",&val);
    put(val);
    c++;
  }
  list *min1,*min2,*p;
  while(OOz(bl,el)==false){
    p=bl;
    while((*p).inf==0)p=(*p).next;
      min1=p;
      while(p!=el){
         p=(*p).next;
         if((*min1).inf>(*p).inf &&(*p).inf!=0)min1=p;
      }
    p=bl;
    while((*p).inf==0 || p==min1)p=(*p).next;
    min2=p;
    while(p!=el){
      p=(*p).next;
if(((*min2).inf>(*p).inf)&& p!=min1 &&(*p).inf!=0)min2=p;
    }
    while((*min1).inf<(*min2).inf)(*min2).inf-=(*min1).inf;
    if((*min1).inf==(*min2).inf)(*min2).inf=0;
    p=bl;
  };
    while((*p).inf==0)p=(*p).next;
    printf("%d",(*p).inf);
};

All the qaetions send to bico@i.kiev.ua..
THANKS A LOT (Beforehand)..
malloc.h
Posted by Leonid Volkov 28 Jan 2003 11:28
I'll ask Pavel Atnashev about it, but I'm quite sure that really,
that is the problem. Try to rewrite the program in C++ style, using
the "new" operator instead of "malloc".
I think there is no malloc.h for UNIX but you can use stdlib.h instead
Posted by abc 2 Feb 2003 17:02
>  Last night I`d finished,compiled,tested the 1053-Problem and after
> sending I received four "Compilation Error"s, while at my computer
> the program functioned normally.
>  I use work with pointers and "<malloc.h>"-standart file,may be
it`s
> my problem.
> I hope for truth...
>
> Program`s cod by C++ Language.
> #include <stdio.h>
> #include <malloc.h>
>
> typedef struct list{
>     list*next;
>     int inf;
> } lst;
> list *bl,*el;
> int c=1;
> void put(int i){
>   list *p;
>   p=(list*)malloc(sizeof(list));
>   (*p).inf=i;
>   if(c==1){ bl=p; el=p;}
>   else{(*el).next=p; el=(*el).next; (*p).next=0;}
> };
> bool OOz(list *b,list *e){
>   if(b==e){(printf("%d",(*b).inf));return true;}
>   bool ans=false;
>   bool c=false;
>   list *p; p=b;
>   while(p!=e){
>     if((*p).inf!=0 && c==false){
>       c=true;
>       ans=true;
>     }
>     else
>     if((*p).inf!=0 && c==true){
>       ans=false;
>       break;
>     }
>   p=(*p).next;
>   }
>   if((*p).inf!=0 && c==true)ans=false;
>   return ans;
> };
>
> void main(){
>   int q=0;
>   scanf("%d",&q);
>   for(int i=0,val;i<q;i++){
>     scanf("%i",&val);
>     put(val);
>     c++;
>   }
>   list *min1,*min2,*p;
>   while(OOz(bl,el)==false){
>     p=bl;
>     while((*p).inf==0)p=(*p).next;
>       min1=p;
>       while(p!=el){
>          p=(*p).next;
>          if((*min1).inf>(*p).inf &&(*p).inf!=0)min1=p;
>       }
>     p=bl;
>     while((*p).inf==0 || p==min1)p=(*p).next;
>     min2=p;
>     while(p!=el){
>       p=(*p).next;
> if(((*min2).inf>(*p).inf)&& p!=min1 &&(*p).inf!=0)min2=p;
>     }
>     while((*min1).inf<(*min2).inf)(*min2).inf-=(*min1).inf;
>     if((*min1).inf==(*min2).inf)(*min2).inf=0;
>     p=bl;
>   };
>     while((*p).inf==0)p=(*p).next;
>     printf("%d",(*p).inf);
> };
>
> All the qaetions send to bico@i.kiev.ua..
> THANKS A LOT (Beforehand)..