牛客网练习5

时间:2023-02-13 19:36:37
链接: https://www.nowcoder.com/questionTerminal/79db907555c24b15a9c73f7f7d0e2471
来源:牛客网

大家应该都会玩“锤子剪刀布”的游戏:

现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
输入描述:
输入第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
= 0
= 1
= int ( input ())
while k < = N:
     a, b  = input ().split()
     if = = b:
         + = 1
     elif = = 'C' and = = 'J' :
         w1c  + = 1
     elif = = 'B' and = = 'C' :
         w1b  + = 1
     elif = = 'J' and = = 'B' :
         w1j  + = 1
     elif = = 'J' and = = 'C' :
         w2c  + = 1
     elif = = 'C' and = = 'B' :
         w2b  + = 1
     elif = = 'B' and = = 'J' :
         w2j  + = 1
     + = 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' )