2012年11月20日 星期二

撲克牌的判斷

輸入5張牌
判斷是什麼牌型。

輸入:
黑桃A 黑桃2 黑桃3 黑桃4 黑桃5

輸出:
同花順

2 則留言:

  1. Dim flower, continuous, havdo As Boolean
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do
    Line Input #1, strr
    colorr = Split("黑桃 紅桃 方塊 梅花", " ")
    flower = False
    For i = 0 To 3
    ori = Len(strr)
    strr = Replace(strr, colorr(i), "")
    If ori - Len(strr) = 10 Then flower = True: Exit For
    Next

    For ii = 1 To 13
    ori = Len(strr)
    strr = Replace(strr, ii, "")
    If ori - Len(strr) = 1 Then List1.AddItem ii + 10000
    If ori - Len(strr) = 2 Then couple = couple + 1
    If ori - Len(strr) = 3 Then three = three + 1
    If ori - Len(strr) = 4 Then four = four + 1
    Next

    continuous = False
    If Val(List1.List(0)) + 1 = Val(List1.List(1)) And Val(List1.List(1)) + 1 = Val(List1.List(2)) And Val(List1.List(2)) + 1 = Val(List1.List(3)) And Val(List1.List(3)) + 1 = Val(List1.List(4)) Then continuous = True: havedo = True
    If Val(List1.List(0)) - 10000 = 1 And Val(List1.List(1)) - 10000 = 10 And Val(List1.List(2)) - 10000 = 11 And Val(List1.List(3)) - 10000 = 12 And Val(List1.List(4)) - 10000 = 13 Then continuous = True: havedo = True
    If continuous = True And flower = True Then Print #2, "同花順": havedo = True
    If continuous = True And flower = False Then Print #2, "順子": havedo = True
    If four = 1 Then Print #2, "四條": havedo = True
    If three = 1 And couple = 1 Then Print #2, "葫蘆": havedo = True
    If couple = 2 Then Print #2, "兩對": havedo = True
    If couple = 1 And three = 0 Then Print #2, "一對": havedo = True
    If havedo = False Then Print #2, "雜牌"
    List1.Clear: couple = 0: three = 0: four = 0: havedo = False
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim b(4) As String
    Dim c(4), tong, sun, shi, mem As Integer
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    a = Split(x)
    For i = 0 To 4
    a(i) = Replace(a(i), "A", 1): a(i) = Replace(a(i), "J", 11)
    a(i) = Replace(a(i), "Q", 12): a(i) = Replace(a(i), "K", 13)
    b(i) = Left(a(i), 2): c(i) = Val(Right(a(i), Len(a(i)) - 2))
    Next i
    i = 0: shi = 1: mem = c(0)
    For j = i + 1 To 4
    If c(j) = c(i) + (j - i) And b(i) = b(j) Then tong = tong + 1
    If c(j) = c(i) + (j - i) Then sun = sun + 1
    If c(i) = c(j) And c(j) = mem Then shi = shi + 1
    Next j
    If tong = 4 Then Print #2, "同花順": End
    If sun = 4 Then Print #2, "順子": End
    If shi = 4 Then Print #2, "四條": End
    If shi = 3 And c(3) = c(4) Then Print #2, "葫蘆": End
    If shi = 2 Then
    For i = 0 To 4
    For j = i + 1 To 4
    If i <> j Then
    If c(i) = c(j) Then ans = ans + 1
    End If
    Next j
    Next
    If ans = 2 Then Print #2, "兩對": End
    If ans = 1 Then Print #2, "一對": End
    End If
    Print #2, "雜牌"
    Close #2
    Close #1
    End
    End Sub

    回覆刪除