Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

The lead game...Why do i get wrong answer

$
0
0

include <stdio.h>

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

scanf("%d", &numberOfRounds);

if(numberOfRounds <= 10000) {
for(int i = 0; i<numberOfRounds; i++){
    int pOne = 0, pTwo = 0;
    scanf("%d %d", &pOne, &pTwo);
    if((pOne > 0) && (pOne <= 10000)) {
        playerOne[i] = pOne;
    }
    else {
        break;
    }
    if((pTwo > 0) && (pTwo <= 10000)) {
        playerTwo[i] = pTwo;
    }
    else {
        break;
    }
}
}

int scoreOne = 0 , scoreTwo = 0;
for(int j = 0; j<numberOfRounds; j++){
    if(playerOne[j] > playerTwo[j]) {
        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;

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>