Loading...
Loading...
Loading...
Four players, numbered 1 to 4, play a quiz with negative marking. Read their scores in order and print the top score and who got it. If two or more players share the top score, name the one with the smallest player number.
Player P scored S.Example 1
Input
45 88 72 60
Output
Player 2 scored 88
Player 2 has the highest score.
Example 2
Input
70 90 90 15
Output
Player 2 scored 90
Players 2 and 3 tie; player 2 has the smaller number.
Try the problem first. Open one hint at a time.
Keep two variables: the best score so far and the player who has it. Start with player 1.
Compare with players 2, 3 and 4 in turn. Replace only when the new score is strictly greater, so ties keep the earlier player.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor