撲克牌發牌期末報告內容: 首先將 52 張牌發成 4 份玩橋牌,再以橋牌的方式排列四組牌 ,花色由黑桃 -> 紅心 -> 磚塊 -> 梅花, 每一個花色都由小至大排列。煩提供程式碼內容
2006-05-28 15:11:30 · 1 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
'表單置1CommandButtonPrivate Sub Command1_Click() Dim A(3, 12) As Integer, B(51) As Boolean, I%, J%, N%, T% Cls '隨機發牌 Randomize For I = 0 To 12 For J = 0 To 3 Do N = Int(Rnd * 52) Loop Until B(N) = False B(N) = True A(J, I) = N Next Next '排序 For N = 0 To 3 For I = 0 To 12 For J = I To 12 If A(N, I) > A(N, J) Then T = A(N, I): A(N, I) = A(N, J): A(N, J) = T End If Next Next Next '輸出 For I = 0 To 3 Print "第"; I + 1; "家" For J = 0 To 12 Print SWAP(A(I, J)); Next Print Tab(2) NextEnd SubFunction SWAP(ByVal N As Integer) As String '換算花色 Select Case N \ 13 Case 0: SWAP = "黑桃)" Case 1: SWAP = "紅心)" Case 2: SWAP = "磚塊)" Case 3: SWAP = "梅花)" End Select SWAP = "(" & N Mod 13 + 1 & SWAPEnd Function
2006-05-29 16:07:28 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋