描述
本题限定用以下方法打乱序列中的元素
random.shuffle()
?几个人用一副扑克牌玩游戏,游戏过程通常有洗牌、发牌、理牌等动作,编写程序模拟游戏过程。新牌花色顺序为?、?、?、?,分别用['s', 'h', 'c', 'd']来表示黑桃、红桃、梅花、方块。花色相同时按2、3、4、5、6、7、8、9、10、J、Q、K、A,最后是小王和大王,小王用'jokers'、大王用 'JOKERS'表示。????????????????????????????????????????????????????????????????????????????????
按以下要求编写程序:????????????????????????????????????????????????????????????????????????????????
按顺序输出新牌
洗牌
按洗好的顺序输出洗过的牌
将牌轮流分给参与游戏的人,按分牌的顺序输出每个人手上的牌
对每个人手上的牌升序排序并输出
输出时,每张牌间用空格分隔
输入
输入一个正整数表示参与游戏的人数,题目限定使每个人分到的牌数相同,即人数为54的约数????????????????????????????????????????????????????????????????????????????????
输入一个正整数表示随机数种子,本题使用随机数种子保证产生序列的稳定性来完成自动评测????????????????????????????????????????????????????????????????????????????????
输出
按顺序输出新牌 按洗好的顺序输出洗过的牌 按分牌的顺序输出每个人手上的牌 输出每个人手上升序排序的牌
输入输出示例
| 输入 | 输出 | 示例 1 | 4
1024 | 参与游戏的人数:4
新牌顺序
s2?s3?s4?s5?s6?s7?s8?s9?s10?sJ?sQ?sK?sA?h2?h3?h4?h5?h6?h7?h8?h9?h10?hJ?hQ?hK?hA?c2?c3?c4?c5?c6?c7?c8?c9?c10?cJ?cQ?cK?cA?d2?d3?d4?d5?d6?d7?d8?d9?d10?dJ?dQ?dK?dA?jokers?JOKERS
洗牌顺序
d6?h2?cA?h3?d3?dJ?h5?h10?s9?h4?h8?hA?c10?cK?h6?sA?h7?s6?c7?cQ?cJ?s2?sQ?d8?sK?s5?c5?d2?dQ?s4?jokers?s7?hJ?d9?JOKERS?c3?sJ?c2?d4?d5?s10?d10?dK?d7?hQ?c8?c4?s8?c9?h9?hK?c6?s3?dA
每个人手上分到的牌
d6?d3?s9?c10?h7?cJ?sK?dQ?hJ?sJ?s10?hQ?c9?s3
h2?dJ?h4?cK?s6?s2?s5?s4?d9?c2?d10?c8?h9?dA
cA?h5?h8?h6?c7?sQ?c5?jokers?JOKERS?d4?dK?c4?hK
h3?h10?hA?sA?cQ?d8?d2?s7?c3?d5?d7?s8?c6
每个人手上排序的牌
s3?s9?s10?sJ?sK?h7?hJ?hQ?c9?c10?cJ?d3?d6?dQ
s2?s4?s5?s6?h2?h4?h9?c2?c8?cK?d9?d10?dJ?dA
sQ?h5?h6?h8?hK?c4?c5?c7?cA?d4?dK?jokers?JOKERS
s7?s8?sA?h3?h10?hA?c3?c6?cQ?d2?d5?d7?d8 |
import random
h=int(input())
n=int(input())
random.seed(n)
list1 = ["2","3","4","5","6","7","8","9","10","J","Q","K","A"]
list2 = ["s","h","c","d"]
list3 = ["jokers","JOKERS"]
list4 = []
print("参与游戏的人数:",h,sep="")
print("新牌顺序")
for j in range(4):
for i in range(13):
list4.append(list2[j]+list1[i])
for x in range(52):
print(list4[x],'',end='')
print(list3[0],list3[1])
print("洗牌顺序")
list4.append(list3[0])
list4.append(list3[1])
lis=list(list4)
random.shuffle(list4)
for y in range(54):
print(list4[y],'',end='')
print()
print("每个人手上分到的牌")
if h == 3:
list5 = []
list6 = []
list7 = []
for z in range(18):
list5.append(list4[3*z])
list6.append(list4[3*z+1])
list7.append(list4[3*z+2])
for x in range(18):
print(list5[x],'',end='')
print()
for x in range(18):
print(list6[x],'',end='')
print()
for x in range(18):
print(list7[x],'',end='')
print()
elif h == 4:
list5 = []
list6 = []
list7 = []
list8 = []
for z in range(13):
list5.append(list4[4*z])
list6.append(list4[4*z+1])
list7.append(list4[4*z+2])
list8.append(list4[4*z+3])
list5.append(list4[52])
list6.append(list4[53])
for x in range(14):
print(list5[x],'',end='')
print()
for x in range(14):
print(list6[x],'',end='')
print()
for x in range(13):
print(list7[x],'',end='')
print()
for x in range(13):
print(list8[x],'',end='')
print()
list8 = [item for item in lis if item in list8]
elif h == 5:
list5 = []
list6 = []
list7 = []
list8 = []
list9 = []
for z in range(10):
list5.append(list4[5*z])
list6.append(list4[5*z+1])
list7.append(list4[5*z+2])
list8.append(list4[5*z+3])
list9.append(list4[5*z+4])
list5.append(list4[50])
list6.append(list4[51])
list7.append(list4[52])
list8.append(list4[53])
for x in range(11):
print(list5[x],'',end='')
print()
for x in range(11):
print(list6[x],'',end='')
print()
for x in range(11):
print(list7[x],'',end='')
print()
for x in range(11):
print(list8[x],'',end='')
print()
for x in range(10):
print(list9[x],'',end='')
print()
list8 = [item for item in lis if item in list8]
list9 = [item for item in lis if item in list9]
elif h == 6:
list5 = []
list6 = []
list7 = []
list8 = []
list9 = []
list10 = []
for z in range(9):
list5.append(list4[6*z])
list6.append(list4[6*z+1])
list7.append(list4[6*z+2])
list8.append(list4[6*z+3])
list9.append(list4[6*z+4])
list10.append(list4[6*z+5])
for x in range(9):
print(list5[x],'',end='')
print()
for x in range(9):
print(list6[x],'',end='')
print()
for x in range(9):
print(list7[x],'',end='')
print()
for x in range(9):
print(list8[x],'',end='')
print()
for x in range(9):
print(list9[x],'',end='')
print()
for x in range(9):
print(list10[x],'',end='')
print()
list8 = [item for item in lis if item in list8]
list9 = [item for item in lis if item in list9]
list10 = [item for item in lis if item in list10]
print("每个人手上排序的牌")
list5 = [item for item in lis if item in list5]
list6 = [item for item in lis if item in list6]
list7 = [item for item in lis if item in list7]
if h == 3:
for x in range(18):
print(list5[x],'',end='')
print()
for x in range(18):
print(list6[x],'',end='')
print()
for x in range(18):
print(list7[x],'',end='')
print()
elif h == 4:
for x in range(14):
print(list5[x],'',end='')
print()
for x in range(14):
print(list6[x],'',end='')
print()
for x in range(13):
print(list7[x],'',end='')
print()
for x in range(13):
print(list8[x],'',end='')
print()
elif h == 5:
for x in range(11):
print(list5[x],'',end='')
print()
for x in range(11):
print(list6[x],'',end='')
print()
for x in range(11):
print(list7[x],'',end='')
print()
for x in range(11):
print(list8[x],'',end='')
print()
for x in range(10):
print(list9[x],'',end='')
print()
elif h == 6:
for x in range(9):
print(list5[x],'',end='')
print()
for x in range(9):
print(list6[x],'',end='')
print()
for x in range(9):
print(list7[x],'',end='')
print()
for x in range(9):
print(list8[x],'',end='')
print()
for x in range(9):
print(list9[x],'',end='')
print()
for x in range(9):
print(list10[x],'',end='')
print()
?
|