Skip to content

Commit 971ce17

Browse files
committed
Rock Paper Scissors!
1 parent 2cf3c8a commit 971ce17

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
Problem Link: https://practice.geeksforgeeks.org/problems/rock-paper-scissors/0
3+
4+
The RPS world championship is here. Here two players A and B play the game.
5+
You need to determine who wins.
6+
Both players can choose moves from the set {R,P,S}.
7+
The game is a draw if both players choose the same item.
8+
The winning rules of RPS are given below:
9+
10+
Rock crushes scissor
11+
Scissor cuts paper
12+
Paper envelops rock
13+
Input:
14+
The first line of input contains T denoting the number of testcases. T testcases follow.
15+
Each testcase contains single line of input that contains two characters sidebyside.
16+
These characters denote the moves of players A and B respectively.
17+
18+
Output:
19+
For each testcase, in a newline, print the winner. If match is draw, print 'DRAW'.
20+
21+
Constraints:
22+
1<= T <= 50
23+
24+
Example:
25+
Input:
26+
7
27+
RR
28+
RS
29+
SR
30+
SP
31+
PP
32+
PS
33+
RP
34+
35+
Output:
36+
DRAW
37+
A
38+
B
39+
A
40+
DRAW
41+
B
42+
B
43+
"""
44+
def rock_paper_scissor(game):
45+
if game[0] == game[1]:
46+
return "DRAW"
47+
if game[0] == "R":
48+
if game[1] == "S":
49+
return "A"
50+
return "B"
51+
if game[0] == "P":
52+
if game[1] == "R":
53+
return "A"
54+
return "B"
55+
if game[0] == "S":
56+
if game[1] == "P":
57+
return "A"
58+
return "B"
59+
60+
for _ in range(int(input())):
61+
game = input()
62+
print(rock_paper_scissor(game))

0 commit comments

Comments
 (0)