小Byte和小Dance玩一種叫“開(kāi)火車(chē)的”紙牌游戲,游戲規(guī)則如下:
1.初始給兩人隨機(jī)平分52張撲克牌,每個(gè)人26張;
2.小Byte先開(kāi)始,將第一張牌放下;
3.隨后兩人輪流按序(按從第一張到最后一張的順序出牌,手中牌的順序不可以被打亂)放置撲克,后一張撲克壓在前一張撲克上;
4.如果出現(xiàn)之前放下的某張撲克s和將要放下的撲克t點(diǎn)數(shù)相同,則當(dāng)前玩家獲得從s到t之間所有的牌(包括s和t這兩張);
5.玩家手上26張牌都出完后,清點(diǎn)雙方獲得的牌數(shù),牌數(shù)多的玩家獲勝,若相同,則平局。
輸入描述:
輸入包括兩行,每行26個(gè)數(shù)字,分別表示兩位玩家初始被隨機(jī)分配的點(diǎn)數(shù),第一行為小byte分到的牌。
輸出描述:
若平局,則輸出"Draw",否則輸出獲勝玩家的名字(“Byte”或"Dance").
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Byte
=
[
10
,
2
,
5
,
6
,
13
,
11
,
11
,
4
,
10
,
8
,
12
,
5
,
4
,
1
,
8
,
1
,
7
,
12
,
4
,
13
,
6
,
9
,
9
,
9
,
5
,
7
]
Dance
=
[
6
,
3
,
13
,
8
,
2
,
3
,
7
,
3
,
2
,
2
,
12
,
11
,
10
,
6
,
10
,
1
,
1
,
12
,
3
,
5
,
7
,
11
,
13
,
4
,
8
,
9
]
# Byte = raw_input()
# Dance = raw_input()
# Byte = int(Byte.split(' '))
# Dance = int(Dance.split(' '))
nu_Byte
=
0
# 統(tǒng)計(jì)
nu_Dance
=
0
i
=
0
common
=
[
]
for
j
in
Byte
:
if
j
not
in
common
:
common
.
append
(
j
)
else
:
index
=
common
.
index
(
j
)
# 找出此牌第一次出現(xiàn)的位置索引
current_Byte
=
len
(
common
)
-
index
# 計(jì)算Byte此次可以回收多少?gòu)埮?
nu_Byte
+=
current_Byte
for
a
in
range
(
current_Byte
)
:
common
.
pop
(
)
# 刪除Byte回收過(guò)的牌
if
Dance
[
i
]
not
in
common
:
common
.
append
(
Dance
[
i
]
)
i
+=
1
else
:
index
=
common
.
index
(
Dance
[
i
]
)
# 找出此牌第一次出現(xiàn)的位置索引
current_Dance
=
len
(
common
)
-
index
# 計(jì)算Dance此次可以回收多少?gòu)埮?
nu_Dance
+=
current_Dance
for
b
in
range
(
current_Dance
)
:
common
.
pop
(
)
# 刪除Dance回收過(guò)的牌
if
nu_Byte
==
nu_Dance
:
print
(
'Draw'
)
elif
nu_Byte
<
nu_Dance
:
print
(
'Dance'
)
else
:
print
(
'Byte'
)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
