8、标题:最长的顺子
【最长的顺子】斗地主起源于湖北十堰房县，据说是一位叫吴修全的年轻人根据当地流行的扑克玩法“跑得快”改编的，如今已风靡整个中国，并流行于互联网上。

3-3-3-3-4-4-5-5-6-7-8-9-10-J-Q-K-A
4-5-6-7-8-8-8

9-10-J-Q-K-A

``````def the_longest_chain(my_poker, history_poker):
# 定义一个扑克转数字字典和一个数字转扑克字典（只关心可出顺子的扑克）
s1 = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
s2 = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
poker = {}
poker_reverse = {}
for i in range(len(s1)):
poker[s1[i]] = s2[i]
poker_reverse[s2[i]] = s1[i]
# 计算未出的扑克，去重并排序
my_poker = [poker.get(x) for x in str(my_poker).split('-')]
history_poker = [poker.get(x) for x in str(history_poker).split('-')]
all_poker = [x for x in range(3, 15)] * 4
for i in my_poker + history_poker:
if all_poker.index(i):
all_poker.remove(i)
remain_poker = list(set(all_poker))
remain_poker.sort()
# 找出最长递增子串
tmp_result = []
result = []
for i in range(len(remain_poker) - 1):
tmp_result.append(remain_poker[i])
for j in range(i + 1, len(remain_poker)):
if remain_poker[j] - remain_poker[j - 1] == 1:
tmp_result.append(remain_poker[j])
else:
break
if len(tmp_result) > len(result):
result = tmp_result[:]
tmp_result.clear()
return '-'.join([poker_reverse[x] for x in result])

print(the_longest_chain("3-3-3-3-4-4-5-5-6-7-8-9-10-J-Q-K-A", "4-5-6-7-8-8-8"))
``````