首页
社区
课程
招聘
[原创]第二题算法--拨开乌云见月明
发表于: 2008-10-7 14:33 6925

[原创]第二题算法--拨开乌云见月明

2008-10-7 14:33
6925

第二题算法--拨开乌云见月明

怎么找算法位置的过程就略过了,算法会先计算用户名是否为a-y这25个小写字母,长度是否为12。然后用二重循环比较了一下大小,并统计了各字符的大小顺序,保存到数组tbNO[]中。这里会要求用户名中不能有重复的字符。再对注册码进行了转换,要求为0-3这四种数字,长度不小于53。

然后进入到注册码变换过程。我花了N长时间把这个过程用VB描述了一下:


Private Function CheckKey(UN As String, SN As String) As String
    Dim i As Long, j As Long, k As Long, l As Long
    Dim nRowCount As Long, n108 As Long, n10C As Long, n110 As Long, n114 As Long, n118 As Long, n11C As Long, n120 As Long, n124 As Long
    Dim tbTemp40(MAXLEN - 1) As Long
    Dim tbTemp100(100) As Long
    
    
    Dim tbRet(MAXLEN * 2) As Byte '返回字符串
    Dim tbSN(53) As Long '注册码
    Dim tbNO(MAXLEN - 1) As Long '用户名各字符的大小顺序
    
    
    '----init table------
    '这一段是我添加的,作用是对用户名和注册码进行转换。
    For i = 1 To Len(UN)
        For j = 1 To Len(UN)
            If Mid$(UN, i, 1) > Mid$(UN, j, 1) Then
                tbNO(i - 1) = tbNO(i - 1) + 1
            End If
        Next
    Next
    
    
    For i = 1 To Len(SN)
        tbSN(i - 1) = Val(Mid$(SN, i, 1))
        If i > 53 Then Exit For
    Next
    '--------------------
    
    '4022AC:
    i = 0
    j = 0
    k = 0
    l = 0
    
    '4022C8:
    Do Until i >= MAXLEN
        tbTemp40(i) = &H1E
        i = i + 1
    Loop
    
    nRowCount = 0
    n108 = 0
    
    If tbSN(0) > 0 Then
        nRowCount = MAXLEN \ tbSN(0)
    End If
    
    n10C = 0
    
    '40231B:
    Do Until n108 >= 2
        
        If n10C > 0 Then
            tbTemp40(tbNO(n10C - 1)) = &H1E
        End If
        
        n10C = 0
        
        '402350:
        Do Until n10C >= MAXLEN
            
            If n10C > 0 Then
                tbTemp40(tbNO(n10C - 1)) = &H1E
            End If
            
            If n108 = 0 Then
                tbTemp40(tbNO(n10C)) = &H28
                n10C = n10C + 1
            End If
            
            If n108 = 1 Then
                tbTemp40(tbNO(n10C)) = &H14
                n10C = n10C + 1
            End If
            
            '4023D3:
            k = 0
            For i = 0 To tbSN(0) - 1
                For j = 0 To nRowCount - 1
                    tbTemp100(i * 4 + j) = tbTemp40(k)
                    k = k + 1
                Next
            Next
            
            '402448:
            n110 = 0
            n114 = 0
            For i = 0 To nRowCount - 1
                n110 = tbTemp100(tbSN(1) * 4 + i) + n110
                n114 = tbTemp100(tbSN(2) * 4 + i) + n114
            Next
            
            '4024BD:
            If n110 = n114 Then '==============================================================================================
                If (tbTemp100(tbSN(3) * 4 + tbSN(4))) = (tbTemp100(tbSN(5) * 4 + tbSN(6))) Then
                    
                    If (tbTemp100(tbSN(7) * 4 + tbSN(8))) = (tbTemp100(tbSN(9) * 4 + tbSN(10))) Then
                        tbRet(l) = &H6C '"l"
                        l = l + 1
                    Else
                        tbRet(l) = &H6B '"k"
                        l = l + 1
                    End If
                    
                Else
                    
                    If (tbTemp100(tbSN(7) * 4 + tbSN(8))) = (tbTemp100(tbSN(9) * 4 + tbSN(10))) Then
                        tbRet(l) = &H6A '"j"
                        l = l + 1
                    Else
                        tbRet(l) = &H69 '"i"
                        l = l + 1
                    End If
                    
                End If
            End If
            
            '4025B9:
            If n110 > n114 Then '==============================================================================================
                i = 0
                n118 = 0
                n11C = 0
                
                tbTemp100(tbSN(1) * 4 + tbSN(11)) = tbTemp100(tbSN(12) * 4 + tbSN(13))
                tbTemp100(tbSN(1) * 4 + tbSN(14)) = tbTemp100(tbSN(15) * 4 + tbSN(16))
                tbTemp100(tbSN(1) * 4 + tbSN(17)) = tbTemp100(tbSN(18) * 4 + tbSN(19))
                tbTemp100(tbSN(2) * 4 + tbSN(20)) = tbTemp100(tbSN(21) * 4 + tbSN(22))
                tbTemp100(tbSN(2) * 4 + tbSN(23)) = tbTemp100(tbSN(24) * 4 + tbSN(25))
                tbTemp100(tbSN(2) * 4 + tbSN(26)) = tbTemp100(tbSN(27) * 4 + tbSN(28))
                
                '402712:
                For i = 0 To nRowCount - 1
                    n118 = tbTemp100(tbSN(1) * 4 + i) + n118
                    n11C = tbTemp100(tbSN(2) * 4 + i) + n11C
                Next
                
                If n118 > n11C Then '--------------------------------------------------------------------------
                    If (tbTemp100(tbSN(29) * 4 + tbSN(30))) = (tbTemp100(tbSN(31) * 4 + tbSN(32))) Then
                        tbRet(l) = &H65 '"e"
                        l = l + 1
                    Else
                        tbRet(l) = &H61 '"a"
                        l = l + 1
                    End If
                End If
                
                '4027D7:
                If n118 < n11C Then '--------------------------------------------------------------------------
                    If (tbTemp100(tbSN(33) * 4 + tbSN(34))) > (tbTemp100(tbSN(35) * 4 + tbSN(36))) Then
                        tbRet(l) = &H67 '"g"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(33) * 4 + tbSN(34))) < (tbTemp100(tbSN(35) * 4 + tbSN(36))) Then
                        tbRet(l) = &H66 '"f"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(33) * 4 + tbSN(34))) = (tbTemp100(tbSN(35) * 4 + tbSN(36))) Then
                        tbRet(l) = &H68 '"h"
                        l = l + 1
                    End If
                End If
                
                '4028DF:
                If n118 = n11C Then '--------------------------------------------------------------------------
                    k = 0
                    For i = 0 To tbSN(0) - 1
                        For j = 0 To nRowCount - 1
                            tbTemp100(i * 4 + j) = tbTemp40(k)
                            k = k + 1
                        Next
                    Next
                    
                    '402966:
                    If (tbTemp100(tbSN(37) * 4 + tbSN(38))) > (tbTemp100(tbSN(39) * 4 + tbSN(40))) Then
                        tbRet(l) = &H62 '"b"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(37) * 4 + tbSN(38))) < (tbTemp100(tbSN(39) * 4 + tbSN(40))) Then
                        tbRet(l) = &H63 '"c"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(37) * 4 + tbSN(38))) = (tbTemp100(tbSN(39) * 4 + tbSN(40))) Then
                        tbRet(l) = &H64 '"d"
                        l = l + 1
                    End If
                End If
            End If
            
            '402A5C:
            If n110 < n114 Then '==============================================================================================
                i = 0
                n120 = 0
                n124 = 0
                
                tbTemp100(tbSN(1) * 4 + tbSN(11)) = tbTemp100(tbSN(12) * 4 + tbSN(13))
                tbTemp100(tbSN(1) * 4 + tbSN(14)) = tbTemp100(tbSN(15) * 4 + tbSN(16))
                tbTemp100(tbSN(1) * 4 + tbSN(17)) = tbTemp100(tbSN(18) * 4 + tbSN(19))
                tbTemp100(tbSN(2) * 4 + tbSN(20)) = tbTemp100(tbSN(21) * 4 + tbSN(22))
                tbTemp100(tbSN(2) * 4 + tbSN(23)) = tbTemp100(tbSN(24) * 4 + tbSN(25))
                tbTemp100(tbSN(2) * 4 + tbSN(26)) = tbTemp100(tbSN(27) * 4 + tbSN(28))
                
                '402BB5:
                For i = 0 To nRowCount - 1
                    n120 = tbTemp100(tbSN(1) * 4 + i) + n120
                    n124 = tbTemp100(tbSN(2) * 4 + i) + n124
                Next
                
                '402C0F:
                If n120 > n124 Then '--------------------------------------------------------------------------
                    If (tbTemp100(tbSN(41) * 4 + tbSN(42))) > (tbTemp100(tbSN(43) * 4 + tbSN(44))) Then
                        tbRet(l) = &H66 '"f"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(41) * 4 + tbSN(42))) < (tbTemp100(tbSN(43) * 4 + tbSN(44))) Then
                        tbRet(l) = &H67 '"g"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(41) * 4 + tbSN(42))) < (tbTemp100(tbSN(43) * 4 + tbSN(44))) Then
                        tbRet(l) = &H68 '"h"
                        l = l + 1
                    End If
                End If
                
                '402D17:
                If n120 < n124 Then '--------------------------------------------------------------------------
                    If (tbTemp100(tbSN(45) * 4 + tbSN(46))) = (tbTemp100(tbSN(47) * 4 + tbSN(48))) Then
                        tbRet(l) = &H65 '"e"
                        l = l + 1
                    Else
                        tbRet(l) = &H61 '"a"
                        l = l + 1
                    End If
                End If
                
                '402D8B:
                If n120 = n124 Then '--------------------------------------------------------------------------
                    k = 0
                    For i = 0 To tbSN(0) - 1
                        For j = 0 To nRowCount - 1
                            tbTemp100(i * 4 + j) = tbTemp40(k)
                            k = k + 1
                        Next
                    Next
                    
                    '402E12:
                    If (tbTemp100(tbSN(49) * 4 + tbSN(50))) > (tbTemp100(tbSN(51) * 4 + tbSN(52))) Then
                        tbRet(l) = &H63 '"c"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(49) * 4 + tbSN(50))) < (tbTemp100(tbSN(51) * 4 + tbSN(52))) Then
                        tbRet(l) = &H62 '"b"
                        l = l + 1
                    End If
                    
                    If (tbTemp100(tbSN(49) * 4 + tbSN(50))) = (tbTemp100(tbSN(51) * 4 + tbSN(52))) Then
                        tbRet(l) = &H64 '"d"
                        l = l + 1
                    End If
                End If
            End If
            
        Loop
        
        n108 = n108 + 1
    Loop
    
    CheckKey = StrConv(tbRet, vbUnicode)
End Function

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 7
支持
分享
最新回复 (10)
雪    币: 443
活跃值: (200)
能力值: ( LV9,RANK:1140 )
在线值:
发帖
回帖
粉丝
2
原来如此!!!!!!!!!!!!谢谢!!!!
2008-10-7 15:49
0
雪    币: 503
活跃值: (80)
能力值: (RANK:280 )
在线值:
发帖
回帖
粉丝
3
注册码不是固定值,也是可以变的
2008-10-7 15:58
0
雪    币: 216
活跃值: (26)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
4
注册码不固定哈,有些地方是可变的,偶就提交了俩组不同的...........
2008-10-7 16:55
0
雪    币: 6051
活跃值: (1441)
能力值: ( LV15,RANK:1473 )
在线值:
发帖
回帖
粉丝
5
注册码不是固定的,但是是通用的,不需要列举多个吧?

所以这题的关键还是要找用户名的算法,这才是那片乌云。
2008-10-7 17:09
0
雪    币: 6051
活跃值: (1441)
能力值: ( LV15,RANK:1473 )
在线值:
发帖
回帖
粉丝
6
注册码不是固定的,但是是通用的,不需要列举多个吧?

所以这题的关键还是要找用户名的算法,这才是那片乌云。
2008-10-7 17:10
0
雪    币: 503
活跃值: (80)
能力值: (RANK:280 )
在线值:
发帖
回帖
粉丝
7
把这句话换个角度说也是对的
用户名不是固定的,但是是通用的

这一题实际上是两个strgen
2008-10-7 17:16
0
雪    币: 10749
活跃值: (3262)
能力值: (RANK:520 )
在线值:
发帖
回帖
粉丝
8
注册码有很多个,我列的图中有13个结点是进行比较的地方,每个结点字符互换可以得一组新的注册码
另外,移动3个球的地方,也可以互换得到新的注册码.
也就是天平左边和右边两个球换个位置就构成了新的注册码
2008-10-7 17:20
0
雪    币: 8209
活跃值: (4518)
能力值: ( LV15,RANK:2473 )
在线值:
发帖
回帖
粉丝
9
请用示例说明
2008-10-7 17:27
0
雪    币: 10749
活跃值: (3262)
能力值: (RANK:520 )
在线值:
发帖
回帖
粉丝
10
301 20 21 2022111212313120221322001101020102010200200102
看这个注册码,把20 和21 换个位置就又组新的了
301 21 20 2022111212313120221322001101020102010200200102

漏了,补充下,对于只判断等与不等的结点,两个字符互换可以得倒新的注册码
哎...我脑细胞也损失严重!

请ccfer大侠 审阅!
2008-10-7 17:34
0
雪    币: 249
活跃值: (35)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
11
我提交的第二个注册码也就是互换了2个字符。不知道算不算通过。
2008-10-7 18:51
0
游客
登录 | 注册 方可回帖
返回
//