Could someone help a new c++ learner? — I first wrote it in python3 and got it accepted, but now i'm trying to reproduce the same results in c++ to improve my non existing coding skills and got wrong answers, which i'm unable to reproduce locally where the code works like a charm.
Here's my latest submission:
Here's also my code:
#include <iostream>
using namespace std;
int main(){
// take inputs
long int board_length;
long int price_coordinate_x;
long int price_coordinate_y;
cin >> board_length;
cin >> price_coordinate_x;
cin >> price_coordinate_y;
// starting points for kings
int white_x = 1;
int white_y = 1;
long int black_x = board_length;
long int black_y = board_length;
// Difference between price coordinate points
long int point_difference_white = labs(price_coordinate_x-price_coordinate_y);
long int point_difference_black = labs(price_coordinate_x-price_coordinate_y);
// if x > y => y will be the first value we'll reach
if (price_coordinate_x > price_coordinate_y) {
point_difference_white += labs(white_x-price_coordinate_y);
point_difference_black += labs(black_x-price_coordinate_x);
}
else if (price_coordinate_x < price_coordinate_y) {
point_difference_white += labs(white_x-price_coordinate_x);
point_difference_black += labs(black_y-price_coordinate_y);
}
else {
point_difference_white += labs(white_x-price_coordinate_x);
point_difference_black += labs(black_x-price_coordinate_x);
}
if (point_difference_black >= point_difference_white) {
cout << "White" << endl;
}
else if (point_difference_black < point_difference_white) {
cout << "Black" << endl;
}
return 0;
}