python# coding:utf-8
# 给一副扑克牌,从中抽取若干张,求里面是否有 5 张或者以上的同花顺。
# 思路:
# 1.开始不管花色,数字是顺下来的
# 2. 最后一个数是不是花色
def GetTongHua(li_):
li_ = sorted(li_, reverse=False)
th_li = [] # 同花顺数组
for index, hand in enumerate(li_):
if index == 0:
th_li.append(hand)
continue
if hand == th_li[-1] + 1 and (hand <= 13 or hand <= 26 or hand <= 39 or hand <= 52):
if hand == th_li[-1] + 1:
th_li.append(hand)
if len(th_li) >= 5:
print(th_li)
return True
else:
th_li = []
th_li.append(hand)
return False
li = [3, 15, 9, 19, 1, 12, 17, 14, 16, 10, 18]
print(GetTongHua(li))
本文作者:Eric
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!