来源:牛客网
大家应该都会玩“锤子剪刀布”的游戏:
现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
输入描述:
输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代 表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。
输出描述:
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯 一,则输出按字母序最小的解。
示例1
输入
10 C J J B C B B B B C C C C B J B B C J J
输出
5 3 2 2 3 5 B B
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
w1, w1c, w1b, w1j
=
0
,
0
,
0
,
0
w2, w2c, w2b, w2j
=
0
,
0
,
0
,
0
p
=
0
k
=
1
N
=
int
(
input
())
while
k <
=
N:
a, b
=
input
().split()
if
a
=
=
b:
p
+
=
1
elif
a
=
=
'C'
and
b
=
=
'J'
:
w1c
+
=
1
elif
a
=
=
'B'
and
b
=
=
'C'
:
w1b
+
=
1
elif
a
=
=
'J'
and
b
=
=
'B'
:
w1j
+
=
1
elif
a
=
=
'J'
and
b
=
=
'C'
:
w2c
+
=
1
elif
a
=
=
'C'
and
b
=
=
'B'
:
w2b
+
=
1
elif
a
=
=
'B'
and
b
=
=
'J'
:
w2j
+
=
1
k
+
=
1
print
(
str
(w1c
+
w1b
+
w1j)
+
' '
+
str
(p)
+
' '
+
str
(w2c
+
w2b
+
w2j))
print
(
str
(w2c
+
w2b
+
w2j)
+
' '
+
str
(p)
+
' '
+
str
(w1c
+
w1b
+
w1j))
max1
=
max
(w1c, w1b, w1j)
max2
=
max
(w2c, w2b, w2j)
if
w1c
=
=
max1
and
w1b !
=
max1:
print
(
'C'
, end
=
' '
)
elif
w1b
=
=
max1:
print
(
'B'
, end
=
' '
)
elif
w1c !
=
max1
and
w1b !
=
max1
and
w1j
=
=
max1:
print
(
'J'
, end
=
' '
)
if
w2c
=
=
max2
and
w2b !
=
max2:
print
(
'C'
)
elif
w2b
=
=
max2:
print
(
'B'
)
elif
w2c !
=
max2
and
w2b !
=
max2
and
w1j
=
=
max2:
print
(
'J'
)
|