Rock-Paper-Scissors (APCS 2020-01 Beginner)
Points 100 1.0s 256MLittle Sisi loves playing rock-paper-scissors with her older brother, since it is one of the few games she has a chance of winning. Every day after coming home she asks her brother to play. To beat him, she spends a lot of time at kindergarten working out a strategy and writes down the throws she plans to make. But now that the brother is in junior high with more and more homework, he has no time to plan his throws in advance, so he decides each throw based on Sisi's throws.
Each day the brother only decides his first throw \(F\); after that his strategy is:
- If Sisi played the same throw in the previous two rounds, his next throw is the one that beats Sisi's throw in those two rounds.
- Otherwise, his next throw is the same as Sisi's previous throw.
Throws are denoted \(0\), \(2\), \(5\) for rock, scissors, paper. The rules are: rock (\(0\)) beats scissors (\(2\)), scissors (\(2\)) beats paper (\(5\)), paper (\(5\)) beats rock (\(0\)); two equal throws are a tie.
Write a program that simulates the game and its result.
Input
The first line contains the brother's first throw \(F\).
The second line contains the count \(N\) of Sisi's throws.
The third line contains Sisi's throws \(y_1, y_2, \ldots, y_N\) in order, separated by spaces.
Constraints
- Every throw is \(0\), \(2\), or \(5\) (\(0\) rock, \(2\) scissors, \(5\) paper)
- \(1 \le N \le 10\)
Output
Output a single line: the brother's throw for each round in order, separated by spaces, followed by a colon stating the round in which the game is decided:
- If the brother wins in round \(k\), output
: Won at round k - If the brother loses in round \(k\), output
: Lost at round k - If it is still a tie after all \(N\) rounds, output
: Drew at round N
Scoring
The time limit for each test case is \(1\) second; your score is the sum over the test cases you pass. The subtasks are:
- Subtask 1 (\(20\) points): \(N = 1\).
- Subtask 2 (\(20\) points): \(N = 2\) and \(y_1 \ne y_2\).
- Subtask 3 (\(60\) points): no additional constraints.
Sample Input 1
0
4
2 5 0 2
Sample Output 1
0 : Won at round 1
Sample Input 2
2
2
2 0
Sample Output 2
2 2 : Lost at round 2
Sample Input 3
5
4
5 5 0 0
Sample Output 3
5 5 2 : Lost at round 3
Sample Input 4
5
6
5 5 2 2 0 0
Sample Output 4
5 5 2 2 0 0 : Drew at round 6
Source
APCS programming exam, January 2020, Problem 1.
Log in to write and submit code.
Log in