Page 1 of 1

compile error

Posted: Wed Feb 15, 2006 7:15 pm
by abilendur
can anybody suggest what is wrong with this, it compiles nicely on my home machine g++ with cygwin and on programmingchallenges.com but here I get a compile error (the problem is contest scoreboard)

Code: Select all

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int compare (const void * a, const void * b);

int main(){
    int i,j,k;
    
    int N;   
    cin>>N; //test cases
    cin.get();
	
    //cerr<<"cases "<<N<<endl;
    int times[200][10]; //contestants, problem ::TIME END
    int tried[200][10]; //contestants, problem ::TRIED nr
    bool solved[200][10]; //contestants, problem ::Solved
    int stats[200][3]; //nr solved, penalty
	
	
    bool submit[200];
	
    double scores[200][2];
    
    int nr;
    for(nr=1; nr <= N; nr++) {
	    cerr<<"new case "<<nr<<endl; 
		//init
	    for( i=0; i!= 200; i++){
		    stats[i][0]=0; // 0 solved
            submit[i]=false;
		for( j=0; j!=10; j++){
			tried[i][j]=0;
			solved[i][j]=false;
		}
	    }		    
	
	    int num, prob, time;
	    char state;
	    
	    cin.get();       
        //cerr<<nr<<" "<<prob<<" "<<time<<" "<<state<<endl;
        //cerr<<ss<<endl;
        while( cin.peek() != '\n' && cin.peek() !=EOF ){
            cin>>num>>prob>>time>>state;
            //cin>>nr>>prob>>time>>state;
            cerr<<num<<" "<<prob<<" "<<time<<" "<<state<<endl;
		
            submit[num]=true;
            if( state == 'I' && !solved[nr][ prob] ){    <<<<<<<<<< nr is mistaken for num
                tried[ num][ prob]++;                
            }
            else if( state == 'C' && !solved[nr][ prob] ){ <<<<<<<<      same here
                solved[num][ prob] = true;
                times[num][ prob] = time; 
            }
		
            cin.get();  
            //cerr<<cin.peek()<<" "<<(int)'\n'<<endl;
           // cerr<< s <<"  : "<<s.length()<<endl;
        }
	
        //evaluate score	
        for(i=0; i!=200; i++){ //contestants
            int Nprob=0;
            int penal=0;
            for( j=0; j!= 11; j++){
                if( solved[i][j] ){
                    Nprob++;
                    penal+=times[i][j];
                    penal+=20*tried[i][j]; 
                }
            }
            stats[i][0]=Nprob;
            stats[i][1]=penal;
            stats[i][2]=i;
		
            //scores[i][0]=i;
            //scores[i][1]=(i)*1.e0+(1.e9-penal)*1.e4+Nprob*1.e10;
        }
	
        qsort(stats, 200, 3*sizeof(int), compare);
        //sort( scores, 0, 200);
	
        for(i=0; i!=200; i++){
            //cerr<< i <<" "<<stats[i][0]<<" "<<stats[i][1]<<endl;
            int conNr=stats[i][2] ;
            if( submit[ conNr ] ){            	
                cout<<stats[ i ][2]<<" "<<stats[ i ][0]<<" "<<stats[ i ][1]<<endl;		
            }
        }
        
        //cerr<<N<<" "<<nr<<endl;  
        if( nr != N ) cout<<endl;
     }    
       
    cerr<<endl;       
    cerr<< "time: "<<clock()/(double)CLK_TCK<<" s"<<endl;     
    return 0;
} 

int compare(const void * a, const void * b){
    int *A= (int*)a;
    int *B= (int*)b;
    
    if( A[0] < B[0] ) return 1;
    if( A[0] > B[0] ) return -1;
    
    if( A[1] > B[1] ) return 2;
    if( A[1] < B[1] ) return -2;
        
    if( A[2] > B[2] ) return 3;
    if( A[2] < B[2] ) return -3;
        
    
    cerr<<"Error in sompare"<<endl;
    return 0;
    //return ( *(int*)a - *(int*)b );
}

Posted: Wed Feb 15, 2006 7:28 pm
by helloneo

Code: Select all

   srand( (unsigned)time( NULL ) ); 
to use srand(), you need to include <time.h>
btw why you need that function..?

sorry

Posted: Wed Feb 15, 2006 7:50 pm
by abilendur
Left it in from old times.
Still doesn't compile here any more bugs??

Posted: Wed Feb 15, 2006 7:57 pm
by Krzysztof Duleba
Actually srand comes from <cstdlib>.

You need to include <ctime> for time and clock and <cstdlib> for srand and qsort. Anyway, qsort is old and slow and just plain ugly, use std::sort instead.

Posted: Wed Feb 15, 2006 8:46 pm
by abilendur
fixed include files
qsort looks fine to me, dont have to mess with redefining any operators

still junk

Posted: Wed Feb 15, 2006 8:56 pm
by abilendur
just got Solved from both, beats me why the sucker wouldnt compile

clock()/(double)CLK_TCK seamed to cause some problems tough