劃拳是古老中國酒文化的一個有趣的組成部分。酒桌上兩人劃拳的方法為:每人口中喊出一個數字,同時用手比劃出一個數字。如果誰比劃出的數字正好等于兩人喊出的數字之和,誰就輸了,輸家罰一杯酒。兩人同贏或兩人同輸則繼續下一輪,直到唯一的贏家出現。
下面給出甲、乙兩人的酒量(最多能喝多少杯不倒)和劃拳記錄,請你判斷兩個人誰先倒。
輸入格式:
輸入第一行先后給出甲、乙兩人的酒量(不超過100的非負整數),以空格分隔。下一行給出一個正整數N(≤100),隨后N行,每行給出一輪劃拳的記錄,格式為:
甲喊 甲劃 乙喊 乙劃
其中喊是喊出的數字,劃是劃出的數字,均為不超過100的正整數(兩只手一起劃)。
輸出格式:
在第一行中輸出先倒下的那個人:A代表甲,B代表乙。第二行中輸出沒倒的那個人喝了多少杯。題目保證有一個人倒下。注意程式處理到有人倒下就終止,后面的資料不必處理。
輸入:
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
輸出:
A
1
求問一下這道編程題怎么做啊
用Python的方法!!
uj5u.com熱心網友回復:
result = [[0, False, 'A'], [0, False, 'B']]
with open(r'c:\zzz.txt', encoding='utf-8', mode='r+') as f:
l = f.read().splitlines()
A, B = map(int, l[0].split())
count = int(l[1])
for i in range(count):
Aj, Ah, Bj, Bh = map(int, l[2+i].split())
if Aj + Bj == Ah and Aj + Bj == Bh:
continue
elif Aj + Bj != Ah and Aj + Bj != Bh:
continue
elif Aj + Bj == Ah and Aj + Bj != Bh:
result[0][0] += 1
else:
result[1][0] += 1
if result[0][0] > A:
result[0][1] = True
break
if result[1][0] > B:
result[1][1] = True
break
print(str(list(filter(lambda x: x[1], result))[0][2]))
print(str(list(filter(lambda x: not x[1], result))[0][0]))
這個意思?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/7031.html
