2010年3月7日 星期日

因數的次方表達處理

image

'因數的次方表達處理
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a() = {2, 2, 2, 3, 3, 5, 7, 7}
        Dim str1 = ""
        Dim p = 0
        Dim n = 1
        For i = 0 To a.Length - 1
            Dim c = a(i)
            If c <> p Then
                If str1 = "" Then
                    str1 = str1 & c & "^"
                Else
                    str1 = str1 & n & "*" & c & "^"
                End If
                n = 1
            Else
                n = n + 1
            End If
            p = c
        Next
        str1 = str1 & n
        str1 = Replace(str1, "^1", "")
        MsgBox(str1)
    End Sub
End Class

沒有留言: