Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
谁是冠军.py 1.28 KB
Copy Edit Web IDE Raw Blame History
徒步天下 authored 2018-02-08 15:16 . 新建 谁是冠军.py
""" 谁是冠军
有五个运动员(甲、乙、丙、丁、戊)参加运动会,分别获得了一百米、二百米、跳高、跳远和铅球冠军,
现在有另外四个人(A、B、C、D)对比赛的结果进行了描述,分别是:
A说:“乙获得铅球冠军,丁获得跳高冠军”
B说:“甲获得一百米冠军,戊获得跳远冠军”
C说:“丙获得跳远冠军,丁获得二百米冠军”
D说:“乙获得跳高冠军,戊获得铅球冠军”
A、B、C和D四个人每个人的描述都对一句,错一句。
现在根据这四个人的描述猜一下五名运动员各获得了什么项目的冠军?
"""
import itertools
player = ['甲', '乙 ', '丙', '丁', '戊']
gold = ['一百米', '二百米', '跳高', '跳远', '铅球']
gold_list = itertools.permutations(gold)
for g in gold_list:
if ((g[1]=='铅球' and g[3]!= '跳高') or (g[1]!='铅球' and g[3]== '跳高')) \
and ((g[0]=='一百米' and g[4]!='跳远') or (g[0]!='一百米' and g[4]=='跳远')) \
and ((g[2] == '跳远' and g[3] != '二百米') or (g[2] != '跳远' and g[3] == '二百米')) \
and ((g[1] == '跳高' and g[4] != '铅球') or (g[1] != '跳高' and g[4] == '铅球')):
for x in zip(player,g):
print(x)

Comment ( 0 )

Sign in for post a comment