python drinking problem

Problem Description

Boxing is an interesting part of ancient Chinese wine culture. The method for two people at the wine table is to call out a number from each person, and at the same time make a number with their hands. If the number drawn by one person is exactly equal to the sum of the numbers shouted by the two, whoever loses, the loser will be fined a glass of wine. If two people win or lose together, the next round will continue until the only winner appears.

The following is the amount of alcohol (the maximum number of cups you can drink without pour) and the punching record of A and B. Please judge which of the two pour first.

Input format:
Enter the first line of input to give the alcohol volume of A and B (non-negative integer not exceeding 100), separated by spaces. The next line gives a positive integer N (≤100), followed by N lines, each line gives a round of punching records, the format is:

Call A Call A Call B Call B Call

The shout is the number that is shouted, and the stroke is the number that is drawn, both of which are positive integers not exceeding 100 (draw together with both hands).

Output format:
output the person who fell first in the first line: A stands for A, B stands for B. The second line outputs how many cups the person who did not pour has drunk. The title guarantees that one person falls. Note that the program is terminated when someone falls down, and the subsequent data does not need to be processed.

Input example:
1 1
6
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
15 1 1 16

Sample output:
A
1

Code reference

#a b 酒量
atop,btop=[int(s) for s in input().split()]
#测试条数
num=int(input())
#初始化a、b喝酒杯数
alose,blose=0,0
#
for i in range(num):
    ahan,achu,bhan,bchu=[int(s) for s in input().split()]
    #a猜对
    if ahan==achu+bchu and bhan!=achu+bchu:
        blose+=1
        if blose>btop:
            print("loser is b")
            break
    elif bhan==achu+bchu and ahan!=achu+bchu:
        alose += 1
        if alose > btop:
            print("loser is a")
            break

Guess you like

Origin blog.csdn.net/kairui_guxiaobai/article/details/108502929