compile error

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
abilendur
New poster
Posts: 5
Joined: Wed Feb 15, 2006 7:10 pm
Location: Estonia

compile error

Post by abilendur » Wed Feb 15, 2006 7:15 pm

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 );
}
Last edited by abilendur on Wed Feb 15, 2006 9:03 pm, edited 3 times in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Wed Feb 15, 2006 7:28 pm

Code: Select all

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

abilendur
New poster
Posts: 5
Joined: Wed Feb 15, 2006 7:10 pm
Location: Estonia

sorry

Post by abilendur » Wed Feb 15, 2006 7:50 pm

Left it in from old times.
Still doesn't compile here any more bugs??

User avatar
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba » Wed Feb 15, 2006 7:57 pm

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.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

abilendur
New poster
Posts: 5
Joined: Wed Feb 15, 2006 7:10 pm
Location: Estonia

Post by abilendur » Wed Feb 15, 2006 8:46 pm

fixed include files
qsort looks fine to me, dont have to mess with redefining any operators

still junk

abilendur
New poster
Posts: 5
Joined: Wed Feb 15, 2006 7:10 pm
Location: Estonia

Post by abilendur » Wed Feb 15, 2006 8:56 pm

just got Solved from both, beats me why the sucker wouldnt compile

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

Post Reply

Return to “C++”