有时候,话可以反着理解

有时候,话可以反着理解

A、B、C、D、E参加竞赛,根据下列条件哪些人参加了竞赛:
1、A参加时B也参加;
2、B和C只有一个参加;
3、C和D或都参加或都不参加。
4、D和E至少有一个人参加;
5、如果E参加,那么A和D都参加。

data = ["A", "B", "C", "D", "E"]
for a in [0, 1]:
    for b in [0, 1]:
        for c in [0, 1]:
            for d in [0, 1]:
                for e in [0, 1]:
                    if a == 1 and b != 1:
                        continue
                    if (b == 1 and c == 1) or (b == 0 and c == 0):
                        continue
                    if (c == 1 and d == 0) or (c == 0 and d == 1):
                        continue
                    if d == 0 and e == 0:
                        continue
                    if e == 1 and (a == 0 or d == 0):
                        continue
                    result = [a, b, c, d, e]
                    for da, re in zip(data, result):
                        if re == 0:
                            continue
                        print(da, end=" ")
                    print()
D:\Python\Python38\python.exe D:/Python/study/20210722.py
C D 

Process finished with exit code 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值