I can’t figure out way i’m getting wrong answer. I’ve tested the program both with the sample input and a random input. Here’s the code.

#include <stdio.h>

int main(int argc, const char * argv[])
{
const int numberOfRounds = 5;
int playerOne[5], playerTwo[5];

``````for(int i = 0; i<numberOfRounds; i++){ //load users scores
int pOne = 0, pTwo = 0;
scanf("%d %d", &pOne, &pTwo);
playerOne[i] = pOne;
playerTwo[i] = pTwo;
}

int scoreOne = 0 , scoreTwo = 0;
for(int j = 0; j<numberOfRounds; j++){
if(playerOne[j] > playerTwo[j]) {   //find difference between scores and keep highest difference according to each player
int score = playerOne[j] - playerTwo[j];
if(score > scoreOne) {
scoreOne = score;
}
}
else {
int score = playerTwo[j] - playerOne[j];
if(score > scoreTwo) {
scoreTwo = score;
}
}
}

if(scoreOne > scoreTwo) {
printf("%d %d \n", 1, scoreOne);
}
else {
printf("%d %d \n", 2, scoreTwo);
}

return 0;
``````

}

Never mind, I read the problem once and assumed all games were five rounds. I’ll fix that.

@tyrthor
your are considering only individual round scores of two players, instead of that you have to consider the score up to that round for both players and update the maximum.for more clarity observe the two tables given in the problem. add the scores of player one and player two up to that round(for which round ur calculating) and take their diff

1 Like
//