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 1220. Stacks

why? not correct! it can run in my com
Posted by boonserm 11 Apr 2004 15:14
my program use pointer to structure and it can run in my TC

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
 long info;
 struct node *next;
};
typedef struct node *NODE;
NODE getnode(long x)
{
 NODE newnode = (NODE)malloc(sizeof(struct node));
 newnode->info = x;
 newnode->next=NULL;
 return newnode;
}
main()
{
  long n,j,i;
  long no,num;
  char get[20];
  NODE temp;
  NODE stack[1002];
  NODE run;
  memset(stack,NULL,sizeof(stack));
  scanf("%ld",&n);
  for(j=1;j<=n;j++)
  {
   fflush(stdin);
   gets(get);

   if(get[0]=='P'&&get[1]=='U'&&get[2]=='S'&&get[3]=='H')
   {
     i=5;
     no = atoi(get+i);
     for(i=5;get[i]!=' ';i++);
     num = atoi(get+i+1);
     if(stack[no]==NULL)
       stack[no]=getnode(num);
     else
       {
       temp = stack[no];
       stack[no]= getnode(num);
       stack[no]->next=temp;
       }
   }
   else if(get[0]=='P'&&get[1]=='O'&&get[2]=='P')
   {
     i=4;
     no = atoi(get+i);
     if(stack[no]->next==NULL)
     {
      temp = stack[no];
      stack[no]=NULL;
     }
     else
     {
      temp = stack[no];
      stack[no]=stack[no]->next;
     }

     if(stack[1001]==NULL)
       stack[1001]=getnode(temp->info);
     else
       {
       run = stack[1001];
       for(;run->next!=NULL;run=run->next);
       run->next= getnode(temp->info);
       }
     free(temp);
   }
  }
 while(stack[1001]!=NULL)
 {
  printf("%ld",stack[1001]->info);
  stack[1001]=stack[1001]->next;
  if(stack[1001]!=NULL)
  printf("\n");
 }
 return 0;
}