您的位置:程序门 -> vb -> 基础类



关于类似于字典的递归问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于类似于字典的递归问题[已结贴,结贴人:topdog2007]
发表于:2007-10-11 21:37:52 楼主
我想生成长3位包含数字和字母的字符串
结果应该是
000
001
002
  ...
zzx
zzy
zzz
-------------------
想了老半天都解决不了
请高手帮忙整理一下思路,有代码更好.谢谢
发表于:2007-10-11 21:39:311楼 得分:0
递归把头都递成死循环了...汗~~
怎样控制递归的关键点还请高手教教
发表于:2007-10-11 21:54:372楼 得分:10
没有用递归,
vbscript code
private sub form_load() dim i as integer, j as integer, k as integer for i = 48 to 122 for j = 48 to 122 for k = 48 to 122 if (i > 57 and i < 97) or (j > 57 and j < 97) or (k > 57 and k < 97) then else debug.print chr(i) & chr(j) & chr(k) end if next k next j next i end sub
发表于:2007-10-11 22:05:303楼 得分:30
deflng   a-d
sub   list3()
const   s   as   string   =   "0123456789abcdefghijklmnopqrstuvwxyz"
dim   x(46655)   as   string
for   a   =   1   to   36
for   b   =   1   to   36
for   c   =   1   to   36
x(d)   =   mid(s,   a,   1)   &   mid(s,   b,   1)   &   mid(s,   c,   1)
d   =   d   +   1
next   c,   b,   a
debug.print   join(x,   ",")
end   sub
发表于:2007-10-11 22:08:544楼 得分:0
很感谢2楼的支持,但我想要的是递归或更优的算法,而不是循环嵌套.

这样子改下吧,生成不定长度的包含数字和字母的字符串
发表于:2007-10-11 22:13:025楼 得分:0
3楼代码效率好高,值得学习.但要不定长度怎么办呢
发表于:2007-10-11 22:18:546楼 得分:10
每必要递归吧   才3个数字   循环下就好了
添加1个listbox   控件   1个按钮
private   sub   command1_click()
    dim   a   as   byte,   b   as   byte,   c   as   byte,   s1   as   string   *   1,   s2   as   string   *   2,   s3   as   string   *   3
    for   a   =   0   to   35
        if   a   <=   9   then
            s1   =   a
        else
            s1   =   chr(55   +   a)
        end   if
        for   b   =   0   to   35
            if   b   <=   9   then
                s2   =   s1   &   b
            else
                s2   =   s1   &   chr(55   +   b)
            end   if
            for   c   =   0   to   35
                if   c   <=   9   then
                    s3   =   s2   &   c
                else
                    s3   =   s2   &   chr(55   +   c)
                end   if
                list1.additem   s3
            next
        next
        doevents
    next
end   sub
发表于:2007-10-11 22:23:117楼 得分:0
谢谢,请问不定长度怎么办呢?
发表于:2007-10-11 22:56:468楼 得分:0
还是添加1个listbox   和   command按钮
vbscript code
option explicit private sub command1_click() dim n as byte, max, i, k, strtmp() as byte, t as byte, j as integer on error resume next n = val(inputbox"输入字符串长度n:")) if n = 0 then exit sub redim strtmp(n * 2 - 1) max = cdec(36) ^ n cls print max for i = 0 to max - 1 k = i for j = n - 1 to 0 step -1 t = k mod 36 if t <= 9 then strtmp(j * 2) = 48 + t else strtmp(j * 2) = 55 + t end if k = k \ 36 next list1.additem strtmp next end sub

发表于:2007-10-11 22:58:369楼 得分:0
现在用代码识别   看起来眼睛舒服多了


快速检索

最新资讯
热门点击