VB.NET 小程序 4

2018-06-22 07:07:04来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Label1.Text = "原始矩阵:"
        Label2.Text = "鞍点坐标:"

        Dim N, M, i, j, k As Integer
        N = InputBox("请输入矩阵行数", "输入")
        M = InputBox("请输入矩阵列数", "输入")
        Dim a(N, M) As Integer
        Randomize()

        '初始化原始矩阵
        For i = 1 To N
            For j = 1 To M
                a(i, j) = (Rnd() * 20)
            Next
        Next

        '输出原始矩阵到Lable1
        Label1.Text = Label1.Text & Chr(13) & Chr(10)
        For i = 1 To N
            For j = 1 To M
                Label1.Text = Label1.Text & a(i, j) & " "
            Next
            Label1.Text = Label1.Text & Chr(13) & Chr(10)
        Next
        '定义数组以存储行最大值,列最小值位置
        Dim line(N, M + 1), list(N + 1, M) As Integer
        For i = 1 To N
            For j = 1 To M
                line(i, j) = 0
                list(i, j) = 0
            Next
        Next
        '找每行最大值,并将位置记入line矩阵中
        Dim max As Integer = 0
        For i = 1 To N
            For k = 2 To M
                max = 1
                If a(i, max) < a(i, k) Then
                    max = k
                End If
            Next
            line(i, k) = 1
        Next
        '找每列最小值,并将位置记入list中
        Dim min As Integer = 0
        For j = 1 To M
            For k = 2 To N
                min = 1
                If a(min, j) > a(k, j) Then
                    min = k
                End If
            Next
            list(k, j) = 1
        Next
        '判断鞍点
        Dim u As Integer = 0
        For i = 1 To N
            For j = 1 To M
                While line(i, j) And list(i, j)
                    Label2.Text = Label2.Text & " " & "(" & i & "," & j & ")"
                    u += 1
                End While
            Next
        Next
        If u = 0 Then
            Label2.Text = Label2.Text & "此矩阵没有鞍点"
        End If
    End Sub

End Class

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:一步步开发自己的博客 .NET版(11、Web.config文件的读取和修改

下一篇:一个简单得不能再简单的“ORM”了