5.10 · exercise
Rock, paper, scissors referee
Referee one round of rock, paper, scissors. The input holds two moves, player 1's and then player 2's, each written as a number: 0 for rock, 1 for paper, 2 for scissors. Paper covers rock, scissors cut paper, and rock breaks scissors.
Print exactly one line:
player 1 winsorplayer 2 winsdrawwhen both players pick the same moveinvalid movewhen either number is outside 0 to 2; thenmainreturns 1 instead of 0, so whoever ran the program can tell it failed
The starter reads both moves into p1_r and p2_r and holds every message you need. Hint: write out player 1's move minus player 2's for all nine rounds. Only five different gaps turn up, and each one always means the same result.
What is checked
- with the input
1 0the program printsplayer 1 winsand returns 0 - the decisions are made with
cmp - the checker also referees rounds you do not see: every winner, a draw, and moves just outside the range
specification
stdin1 0
stdoutprints the right output
exitexits with the right code
sourceuses
cmphiddenright output and exit code on 7 more inputs you do not see
We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.