一个数组,a(100),如下
  a(0)="12345"
  a(1)="12346"
  a(2)="12347"
  a(3)="12348"
  a(4)="12349"
 现在如果要向这个数组里面再添加一个值a(5),
1. 如果在数组中已经存在,就不添加,
2. 如果要填加的元素更改排列组合的顺序在数组中已经存在,也不添加,比如说现在已经存在  12345 那么,如果要添加的是 54321,则不允许添加.
3. 在以上两种情况之外的,都添加.
哪位能给个思路?或者代码?

解决方案 »

  1.   

    第2个偶只想到了用循环
    判断长度 然后instr
      

  2.   


        Dim a(100) As String
        Dim i As Integer
        Dim s As String    a(0)="12345"
        a(1)="12346"
        a(2)="12347"
        a(3)="12348"
        a(4)="12349"    s = "12366"
        For i = 0 To UBound(a)
            If Switch(a(i) = s, True) Or StrReverse(a(i)) = s Then Exit Sub
            If a(i) = vbNullString Then
                a(i) = s
                Exit For
            End If
        Next
      

  3.   

    是所有组合的话就循环用replace替换,用len比较就是了
      

  4.   

    所有排列组合的顺序的判断:Function Res(ByVal s As String, ByVal a As String) As Boolean
        
        Dim i As Integer
        Dim tmp As String
        
        Res = False
        If Len(s) <> Len(a) Then
            Res = True
            Exit Function
        End If
        
        For i = 1 To Len(s)
            tmp = Mid(s, i, 1)
            If Len(Replace(s, tmp, "")) <> Len(Replace(a, tmp, "")) Then
                Res = True
                Exit Function
            End If
        Next
        
    End Function
    按键:    Dim a(100) As String
        Dim i As Integer
        Dim s As String    a(0)="12345"
        a(1)="12346"
        a(2)="12347"
        a(3)="12348"
        a(4)="12349"    s = "12366"
        For i = 0 To UBound(a)
            If not res(s,a(i)) Then Exit Sub
            If a(i) = vbNullString Then
                a(i) = s
                Exit For
            End If
        Next
      

  5.   

    或者用循环用split分组字符,比较ubound是否一样大小也可以