What kind of c++ complier is suitable for online-judge?

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

Moderator: Board moderators

Post Reply
foolishzhu
New poster
Posts: 4
Joined: Sun Jul 02, 2006 5:00 am

What kind of c++ complier is suitable for online-judge?

Post by foolishzhu »

I write source code under vc++6.0,and it is compiled successfully under it .But when I submit my code to the net ,each time it says compile error!
I am very surprised! Then ,what kind of c++ compiler should I use ?

for example : my code is as follows :


#include <iostream.h>

using namespace std;

class IntNode;
class DynamicIntArr;


class IntNode{

public:
IntNode* next;
int data;
IntNode() : next(0),data(0) {}
~IntNode() {}
};

class DynamicIntArr{

int length;
IntNode* head;
public:
DynamicIntArr():length(0),head(0) {}
int size() {return length;}
void push_back(int);
void pop_back();
int& operator[] (int index);
IntNode* operator() (int index);
~DynamicIntArr();
};

IntNode* DynamicIntArr:: operator() (int index)
{
IntNode* ptr = this->head;
for (int i = 0; i < index; i++)
ptr = ptr->next;

return ptr;
}

void DynamicIntArr::push_back(int data) {

IntNode* newnode = new IntNode;
newnode->data = data;
if (this->length == 0)
{
this->head = newnode;
}
else
{
(*this)(this->length - 1)->next = newnode;
}
this->length++;
}
void DynamicIntArr::pop_back()
{
if (this->length == 0)
return;
if (this->length == 1)
{
delete this->head;
this->head = 0;
}
else
{
IntNode* ptr = (*this)(this->length - 2);
delete ptr->next;
ptr->next = 0;
}
this->length--;
}

int& DynamicIntArr::operator[] (int index)
{
return (*this)(index)->data;
}

DynamicIntArr::~DynamicIntArr()
{
for (int i = 0; i < this->size(); i++)
this->pop_back();
}



int N;
int* Answer;
int Judge(int* Serial);
int Check(int* Serial,int index);

void main()
{
cin >> N;
Answer = new int[N];
for (int i = 0; i < N; i++)
cin >> Answer;
int* arr = new int[N];
DynamicIntArr ResultOut;
while (true)
{
if (!(cin >>arr[0]))
break;
for (i = 1; i < N; i++)
cin >> arr;
ResultOut.push_back(Judge(arr));
}
for (i = 0 ;i < ResultOut.size(); i++)
cout << ResultOut << endl;

delete []Answer;
delete []arr;
Answer = 0;
arr = 0;

}


int Judge(int* Serial)
{
int* SerialinOrder = new int[N];
for (int i = 0; i < N; i++)
{
SerialinOrder[Answer - 1] = Serial;
}
for (i = 0 ; i < N; i++)
Serial = SerialinOrder;

delete []SerialinOrder;
SerialinOrder = 0;

int maxlength = 0;

for (i = 0; i < N; i++)
{
int tmp = Check(Serial,i);
if (tmp > maxlength)
maxlength = tmp;
}
return maxlength;
}

int Check(int* Serial,int index)
{
DynamicIntArr correct;
correct.push_back(Serial[index]);
for (int i = index + 1; i < N; i++)
{
if (Serial > correct[correct.size() - 1])
correct.push_back(Serial);
}
return correct.size();
}
jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes »

you can try to use gcc/g++, and if you're using windows, you can try to use dev cpp... :D
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: What kind of c++ complier is suitable for online-judge?

Post by Martin Macko »

foolishzhu wrote:I write source code under vc++6.0,and it is compiled successfully under it .But when I submit my code to the net ,each time it says compile error!
The errors g++ 3.4.6 gives are

Code: Select all

In file included from /usr/lib/gcc/i686-pc-linux-gnu/3.4.6/include/g++-v3/backward/iostream.h:31,
                 from test.cc:1:
/usr/lib/gcc/i686-pc-linux-gnu/3.4.6/include/g++-v3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
test.cc:92: error: `main' must return `int'
test.cc:92: error: return type for `main' changed to `int'
test.cc: In function `int main(...)':
test.cc:103: error: name lookup of `i' changed for new ISO `for' scoping
test.cc:95: error:   using obsolete binding at `i'
test.cc: In function `int Judge(int*)':
test.cc:125: error: name lookup of `i' changed for new ISO `for' scoping
test.cc:121: error:   using obsolete binding at `i'
The first one you can avoid by writing
#include <iostream>
instead of
#include <iostream.h>
Further your main funcion shoud return int, therefore you should write
int main()
{
...........
}
instead of
void main()
{
...........
}
Finally, to avoid the last two compile errors you should note that a variable declared in a for loop if local the this loop. You can correct your code by writing
for (int i = 0; i < N; i++)
{
........SerialinOrder[Answer[i] - 1] = Serial[i];
}
for (int i = 0 ; i < N; i++)
........Serial[i] = SerialinOrder[i];
instead of
for (int i = 0; i < N; i++)
{
........SerialinOrder[Answer[i] - 1] = Serial[i];
}
for (i = 0 ; i < N; i++)
........Serial[i] = SerialinOrder[i];
in function Judge. The error in the function main may by corrected similarly.
Post Reply

Return to “C++”