本文介绍了如何编写置换代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

此代码为组合代码,但如何按照下面的代码编写置换代码;

This code for combination ,but how to write the permutation code following coding bellow;

    Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With ListBox1
            .Items.Add("7093,1688,5547,0157,7902,0911,5194,1601,7555,0578,6923,6028,2953,3100,3566,2786,1306,2211,1023,0287,9287,1300,5439")
            .Items.Add("9742,7504,3500,4341,3039,0495,2005,2292,0331,8725,0397,2075,7599,4766,9247,7718,6644,7209,1889,6381,8869,4744,5254")
        End With
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        For I As Integer = 0 To ListBox1.Items.Count - 1
            Dim StringToCheck As String = CStr(ListBox1.Items(I))
            StringToCheck = StringToCheck.Replace(vbCrLf, ",")

            Dim StringsToCheck As String() = StringToCheck.Split(","c)

            For Each S As String In StringsToCheck
                Console.WriteLine(S)

                Dim StringsToFind As String() = {S(0) & S(1), _
                                 S(0) & S(2), _
                                 S(0) & S(3), _
                                 S(1) & S(2), _
                                 S(1) & S(3), _
                                 S(2) & S(3), _
                                 S(0) & S(1) & S(2), _
                                 S(0) & S(1) & S(3), _
                                 S(0) & S(2) & S(3), _
                                 S(1) & S(2) & S(3), _
                                 S(0) & S(1) & S(2) & S(3)}

                Dim Count As Integer = 0
                For Each Find As String In StringsToFind
                    Count = 0
                    For Each Check As String In StringsToCheck
                        Select Case (Find.Count)
                            Case 2
                                If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) Then Count += 1
                            Case 3
                                If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) AndAlso Check.Contains(Find(2)) Then Count += 1
                            Case 4
                                If Check.Contains(Find(0)) AndAlso Check.Contains(Find(1)) AndAlso Check.Contains(Find(2)) AndAlso Check.Contains(Find(3)) Then Count += 1

                        End Select
                    Next
                    ListBox2.Items.Add("Occurances (" & S & ", " & Find & ")= " & Count.ToString)
                Next
            Next

        Next



    End Sub

推荐答案


这篇关于如何编写置换代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 01:51
查看更多