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 1003. Parity

Why my program get compilation error ???? HELP--for 1003
Posted by Turing@ZJU.acm 15 Feb 2002 22:07
#include <stdio.h>
#include <string.h>
#include <alloc.h>


#define inFile "1003.in"
#define outFile "1003.out"

struct node {
    long c1,c2 ;
    int xx ;
    struct node /**/ *next ;
} ;


FILE *fp1,*fp2 ;
node /**/ *Head ;
int Flag , Result ;

void Init () ;
void Work () ;
void Done ( int , int , int ) ;
void Link ( int v1 , int v2 , int shi );
void Remove ( node * now )             ;

void main( int argc , char * argv[] )
{
//    fp1 = fopen ( argv [1 ] , "rt" ) ;
//    fp2 = fopen ( argv [2 ] , "wt" ) ;
    Init () ;
    Work () ;
//    fclose ( fp1 ) ;
//    fclose ( fp2 ) ;

}

void Init ()
{

    Head = (struct node * ) /**/malloc (sizeof ( struct
node ) ) ;
    Head -> c1 = 0 ;
    Head -> c2 = 0 ;
    Head -> xx = 0 ;
    Head -> next = NULL ;
}

void Work ()
{
    long www ;
    int num ;
    long v1, v2 ;
    char ss [10 ] ;
    scanf (  "%ld" , &www ) ;
    while ( www != -1 ) {
        Flag = 1 ;
        scanf (   "%d" , &num ) ;
        for ( int i = 0 ; i < num ; i ++ ) {
            scanf (   "%ld %ld %s" , &v1 , &v2 ,
ss ) ;
            if ( Flag ) {
                if ( strcmp ( ss , "even" ) ==
0 )
                    Done ( v1 , v2 , 2 ) ;
                else Done ( v1 , v2 , 1 ) ;
                Result = i ;
            }
        }
        printf (   "%d\n" , Result ) ;
        scanf (   "%ld" , &www ) ;
    }
}

void Done ( int v1 , int v2 , int shi )
{
    node /**/ *p ;
    int mode = 0 ;

    if ( Head -> next == NULL )
        Link ( v1,v2,shi ) ;
    else {
        p = Head -> next ;
        while ( p ) {
            if ( p->c1 == v1 ) {
                mode = 1 ;
                break ;
            } else if ( p->c2 == v2 ) {
                mode = 2;
                break ;
            }
            p = p -> next ;
        }
        if ( mode == 0 ) {
            Link ( v1,v2,shi ) ;
        } else if ( mode == 1 ) {
            if ( p->c2 == v2 ) {
                if ( p->xx != shi )
                    Flag = 0 ;
            } else if ( p->c2 > v2 ) {
                int max = p->c2 ;
                if ( p->xx == shi ) {
                    p->xx = 2;
                    p->c2 = v2 ;
                    Done ( v2+1 , max ,
2 ) ;
                } else {
                    p->xx = shi ;
                    Done ( v2+1 , max ,
1 ) ;
                }
            } else {
                if ( p ->xx == shi )
                    Done ( p->c2 , v2-1 ,
2 ) ;
                else Done ( p->c2 , v2-1 , 1 ) ;
            }
        } else if ( mode == 2 ) {
            if ( p->c1 == v1 ) {
                if ( p->xx != shi )
                    Flag = 0 ;
            } else if ( p->c1 < v1 ) {
                int max = p->c1 ;
                if ( p->xx == shi ) {
                    p->xx = 2;
                    p->c1 = v1 ;
                    Done ( max , v1-1 ,
2 ) ;
                } else {
                    p->xx = shi ;
                    Done ( max, v1-1 , 1 ) ;
                }
            } else {
                if ( p ->xx == shi )
                    Done ( v1 , p->c1-1 ,
2 ) ;
                else Done ( v1 , p->c1-1 , 1 ) ;
            }




        }


    }


}

void Link ( int v1 , int v2 , int shi )
{
    node /**/ *pp ;

    pp = ( struct node* ) /**/malloc ( sizeof ( struct node )) ;
    pp -> c1 = v1 ;
    pp -> c2 = v2 ;
    pp -> xx = shi ;
    pp -> next = Head -> next ;
    Head -> next = pp ;
}

void Remove ( node * now )
{
    node /**/ *p = now -> next ;
    now -> next = p -> next ;
    /**/free ( p ) ;
}