I am trying to submit a solution to a problem in TopCoder, which requires a submission to follow its predefined classes and methods. Since I am new to TopCoder, I am mostly trying to adjust to the coding interface. This code compiles perfectly on my computer. Unfortunately on TopCoder, I have been getting the errors:
Your code did not compile:
errors linking:
AdditionGame-stub.o: In function main':
AdditionGame-stub.cc:(.text.startup+0x0): multiple definition of
main'
AdditionGame.o:AdditionGame-stub.cc:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status
Help Please. Here is my code:
class AdditionGame {
public:
int getMaximumPoints(int a, int b, int c, int n){
int temp;
if(a<b){temp=a; a=b; b=temp;}
if(b<c){temp=b; b=c; c=temp;}
int sum=0;
for(int i=0; i<n; i++){
if(a>0){sum=sum+a;}
if(a>0){a=a-1;}
if(a<b){temp=a; a=b; b=temp;}
if(b<c){temp=b; b=c; c=temp;}
}
return sum;
}
};
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
AdditionGame add;
int A,B,C,N;
cin>>A>>B>>C>>N;
int p = add.getMaximumPoints(A, B, C, N);
cout<<p;
return 0;
}`
Looks like TopCoder is defining the main() function for you, based on your error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With