sofeware-acm 0 Newbie Poster

Question :
I use my code test sample which can got the right answer.
But when I upload ACM Judge.
It appear wrong answer.

Could everybody tell me what wrong with me ?
Thank you.


<pre>
Sample Input

The following text<C><B>is centred and in boldface</B></C>#
<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#
<B><C> This should be centred and in boldface, but the
tags are wrongly nested </B></C>#
<B>This should be in boldface, but there is an extra closing
tag</B></C>#
<B><C>This should be centred and in boldface, but there is
a missing closing tag</C>#
#

Sample Output

Correctly tagged paragraph
Correctly tagged paragraph
Expected </C> found </B>
Expected # found </C>
Expected </B> found #

</pre>

#include<stdio.h>
#include<stdlib.h>
#define STACKSIZE 20000


typedef struct{
    int size;
    char items[STACKSIZE];
}STACK ; 

void init(STACK *ps)
{
    ps->size = 0;

}


int compare(STACK *ps,STACK *fs,char x){
    if(ps->items[ps->size-(fs->size+1)] == x) return 1;
    else return 0 ;
}


void push(STACK *ps, char x){
    if (ps->size == STACKSIZE) {
 /*       fputs("Error: stack overflow\n", stderr); */
        abort();
    } else {

        ps->items[ps->size] = x;
/*        printf("<come into push>the stack number : %d the stack element : %c \n",ps->size,ps->items[ps->size]); */
        ps->size++;
      }
}

void pop(STACK *ps){
    if (ps->size == -1){
/*        fputs("Error: stack underflow\n", stderr);  */
        abort();
    } else 
        ps->size--;
}

int empty(STACK *ps){
    if (ps->size == 0){
/*       fputs("Error: stack underflow\n", stderr);  */
       return 1;
    } else
       return 0;

}



int main()
{
  int bytes_read;
  size_t nbytes = 100;
  char *my_string;


  STACK *s,*f; 
  s=(STACK *)malloc (sizeof(STACK));
  f=(STACK *)malloc (sizeof(STACK));





/*  printf("point %d",s->size); */
  

  /* These 2 lines are the heart of the program. */
  my_string = (char *) malloc (nbytes + 1);



  while((my_string[0]!='#')){
         
         int i=-1; /*  This is for (   while((my_string[i++] != '#'))  )  */
/*       puts ("Please enter a line of text.");  */
         bytes_read = getline(&my_string, &nbytes, stdin);
       if(my_string[0]=='#'){
          break;
       }  
       else{
 
       while(  bytes_read > i ){
              i++;
/*              printf("first while :The sequence : %d The letter : %c \n",i,my_string[i]);   */
              if(my_string[i] == '#'){
                     if(s->size == 1 ){
                        printf("Expected </%c> found #\n",s->items[s->size-1]);
                        init(s);
                        init(f);
                     }
                     else if(f->size == 1){
                        printf("Expected # found </%c>\n",f->items[f->size-1]);
                        init(s);
                        init(f);
                     }
                     else if(f->size == 2){
                        printf("Expected </%c> found </%c>\n",f->items[f->size-1],f->items[f->size-2]);                      
                        init(s);
                        init(f);
                     }
                     else{
                        printf("Correctly tagged paragraph\n");
                        init(s);
                        init(f);
                     }

              }/* (my_string[i] == '#')  */
              else{
                     
                      if(   (my_string[i] == '<')  &&   ( my_string[i+1] >= 'A' )   &&  ( my_string[i+1] <= 'Z')    &&    (( my_string[i+2] <= '>')) ){
                             push(s,my_string[i+1]);
                      } 
                      else{
                               if(   (my_string[i] == '<')  &&  ( my_string[i+1] >= '/' )   &&   ( my_string[i+2] >= 'A' )   &&  ( my_string[i+2] <= 'Z')    &&    (( my_string[i+3] <= '>')) ){                         
                                         if(  compare(s,f,my_string[i+2])  ){
                                                pop(s);
                                         }
                                         else{
                                               push(f,my_string[i+2]);
                                         }    
                                }
                                                          


                       } 

              }
       
       }/*  while(   (bytes_read > i) )  */
       }
  }  /* while((my_string[0]!='#'))  */
   
   

  return 0;
}

/*
 The following text<C><B>is centred and in boldface</B></C>#
 <B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#
 <B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#
 <B>This should be in boldface, but there is an extra closing tag</B></C>#
 <B><C>This should be centred and in boldface, but there is a missing closing tag</C>#

 The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C>#


 The following text<C><B>is centred and in boldface</B></C>#<B>This <\g>is <B>boldface</B> in <<*> a</B> <\6> <<d>sentence#<B><C> This should be centred and in boldface, but the tags are wrongly nested </B></C>#<B>This should be in boldface, but there is an extra closing tag</B></C>#<B><C>This should be centred and in boldface, but there is a missing closing tag</C># 
#
*/

/*
 <B>happy</B>#
 http://www.sci.csueastbay.edu/~billard/cs3240/node8.html array stack

*/