求助:谁先倒

Python_changed 2020-09-08 06:51:09
划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就输了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。

下面给出甲、乙两人的酒量(最多能喝多少杯不倒)和划拳记录,请你判断两个人谁先倒。

输入格式:
输入第一行先后给出甲、乙两人的酒量(不超过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的方法!!
...全文
347 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Python_changed 2020-09-15
  • 打赏
  • 举报
回复
[quote=引用 1 楼 chuifengde 的回复:]是这样的,不过我现在还没学到文件这里,,你的回答我有些不太懂
但是可以做出来
谢谢啦~
Python_changed 2020-09-15
  • 打赏
  • 举报
回复
okok,做出来了,谢谢啦
Raaay233 2020-09-15
  • 打赏
  • 举报
回复

a_limit, b_limit = [int(x) for x in input().split()]
n = int(input())
a_count = 0
b_count = 0
for i in range(n):
    tmp = [int(x) for x in input().split()]
    if tmp[0] + tmp[2] == tmp[1] and tmp[0] + tmp[2] != tmp[3]:
        a_count += 1
    elif tmp[0] + tmp[2] != tmp[1] and tmp[0] + tmp[2] == tmp[3]:
        b_count += 1
    if a_count > a_limit:
        print('A')
        print(b_count)
        break
    elif b_count > b_count:
        print('B')
        print(a_count)
        break
大概这个样子
chuifengde 2020-09-09
  • 打赏
  • 举报
回复
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]))
这个意思?

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧