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

The Lead Game....HELP PLEASE

$
0
0

Can somebody please look at my code its submission. The program works just fine for me. The out put with any number entered is right and in the event of a tie the player who had the highest score first wins.

include <stdio.h>

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

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 <= 1000)) {
        playerOne[i] = pOne;
    }
    else {
        break;
    }
    if((pTwo > 0) && (pTwo <= 1000)) {
        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];
            diffOne[j] = score;
        if(score > scoreOne) {
            scoreOne = score;
        }
    }
        if(playerOne[j] < playerTwo[j]) {
        int score = playerTwo[j] - playerOne[j];
            diffTwo[j] = score;
        if(score > scoreTwo) {
            scoreTwo = score;
        }
    }

}

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

if(scoreOne ==  scoreTwo) {
    tieScore = scoreOne;
    for(int k = 0; k<numberOfRounds; k++) {
        if(diffOne[k] == tieScore) {
            printf("%d %d \n", 1, tieScore);
            break;

        }
        if(diffTwo[k] == tieScore) {
            printf("%d %d \n", 2, tieScore);
            break;
        }
    }
}


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>