'第5題 撲克牌(23點),A2~9TJQK分別代表1~13點,但A可換成10點,>23爆
Dim line() = Split(TextBox1.Text, vbNewLine)
Dim n As Integer = Val(line(0))
For i = 1 To n
Label1.Text &= vbCrLf
Dim line1 = line(i)
Dim m = line1.Length
Dim j As Integer
Dim sum = 0, ace = 0
For j = 2 To m Step 2
Dim c = Mid(line1, j, 1)
Select Case c
Case "2" To "9" : sum += Val(c)
Case "A"
sum += 1 '先以 1 點計
ace += 1 'Ace的張數
Case "T" : sum += 10
Case "J" : sum += 11
Case "Q" : sum += 12
Case "K" : sum += 13
End Select
Next
If (sum > 23) Then 'Ace算1點 也爆了
Label1.Text &= "F"
Else
While (ace > 0 And sum < 15) '有Ace而且換10點不會爆,就換1張
sum += 9
ace -= 1
End While
Label1.Text &= sum
End If
Next i
---------第5題 資料---
5
HTDJSACA Ans: 23
DJCQH3 Ans: F
HADAC2SA Ans: 23
H9SACJ Ans: 21
SADKCTH2 Ans: F
0 意見:
張貼留言