问题描述
例如:Dimwz()AsString={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}‘定义一个36位数组Dimsz(10)AsString定义一个10位数组想让sz数组每位值分别为从0-Z,即从0000000000-0000000001-zzzzzzzzzz,怎么循环呢?
解决方案
解决方案二:
解决方案三:
引用1楼xianfajushi的回复:看不懂你的内容
解决方案四:
是否可以输出象这种v3jbovjmmjmyj8o9格式的数字?
解决方案五:
这个结果是非常巨大的。给你写一个简化、可用来测试的版本ModuleModule1SubMain()Dimwz()AsString={"0","1","2","a","b","c"}DimcntAsIntegerForEachrIn组合(wz,3)Dimx=String.Join(String.Empty,r.ToArray)cnt+=1Console.WriteLine("{0}:{1}",cnt,x)NextConsole.WriteLine(".....按任意键结束")Console.ReadKey()EndSubPublicIteratorFunction组合(wzAsString(),countAsInteger)AsIEnumerable(OfList(OfString))If(count<=0)ThenYieldNewList(OfString)ElseForEachkIn组合(wz,count-1)ForEachwInwzDimu=k.ToListu.Add(w)Debug.Assert(u.Count=count)YielduNextNextEndIfEndFunctionEndModule
你可以看到,6个字符,会得到216个结果。
解决方案六:
对于你的问题,就是调用算法时写Dimwz()AsString={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}DimcntAsIntegerForEachrIn组合(wz,10)......................
解决方案七:
引用4楼sp1234的回复:
这个结果是非常巨大的。给你写一个简化、可用来测试的版本ModuleModule1SubMain()Dimwz()AsString={"0","1","2","a","b","c"}DimcntAsIntegerForEachrIn组合(wz,3)Dimx=String.Join(String.Empty,r.ToArray)cnt+=1Console.WriteLine("{0}:{1}",cnt,x)NextConsole.WriteLine(".....按任意键结束")Console.ReadKey()EndSubPublicIteratorFunction组合(wzAsString(),countAsInteger)AsIEnumerable(OfList(OfString))If(count<=0)ThenYieldNewList(OfString)ElseForEachkIn组合(wz,count-1)ForEachwInwzDimu=k.ToListu.Add(w)Debug.Assert(u.Count=count)YielduNextNextEndIfEndFunctionEndModule你可以看到,6个字符,会得到216个结果。
你好,系统不认yield啊,第一次见这个
解决方案八:
上面的“组合”方法,你可以看到,其代码是很简单的,而且逻辑也很简单,就是一个递归嵌套而已。跟你遍历一个“树形”结构等等算法,或者任何一个刚学编程的学生学习“hanoi塔算法”,也是一样的意思。如果你当初没有学好递归,可以复习一下。这里,计算输出的结果是关于“List<string>”对象的枚举。而,要得到一个count个单元的List<string>对象,首先得到一个count-1个单元的对象,然后把最后一个单元(string)追加给List,就能得到count个单元的List。
解决方案九:
引用6楼oxking_ly的回复:
Quote: 引用4楼sp1234的回复:
这个结果是非常巨大的。给你写一个简化、可用来测试的版本ModuleModule1SubMain()Dimwz()AsString={"0","1","2","a","b","c"}DimcntAsIntegerForEachrIn组合(wz,3)Dimx=String.Join(String.Empty,r.ToArray)cnt+=1Console.WriteLine("{0}:{1}",cnt,x)NextConsole.WriteLine(".....按任意键结束")Console.ReadKey()EndSubPublicIteratorFunction组合(wzAsString(),countAsInteger)AsIEnumerable(OfList(OfString))If(count<=0)ThenYieldNewList(OfString)ElseForEachkIn组合(wz,count-1)ForEachwInwzDimu=k.ToListu.Add(w)Debug.Assert(u.Count=count)YielduNextNextEndIfEndFunctionEndModule你可以看到,6个字符,会得到216个结果。
你好,系统不认yield啊,第一次见这个
这需要vs2012版本。你不会是4年之内都没有升级过vs系统吧?
解决方案十:
yield(迭代器)是vb11的特性,随vs2012而发布。上面的测试程序,如果发布目标.net平台为3.0以下,可能会没有tolist函数,所以不能编译通过(你需要自己写一个tolist函数,就能编译了)。而在3.5以上平台,都能编译通过,只要你使用vs2012以上版本开发工具、且.net目标平台是3.5以上,就能支持yield。我们实际开发中,早就使用vs2015,应用编译发布的.net目标平台是4.5以上。
解决方案十一:
除了开发工具升级修复之外,另外,我要说一下,vs2015社区版对于小公司和个人是免费的。我相信你如果用的是vs2010,很可能是盗版的。为什么不改为使用vs2015社区版呢?
解决方案十二:
如果不支持yield,那就这样:SubMain()PrintString(String.Empty,0,10)Console.ReadKey()EndSubSubPrintString(strAsString,positionAsInteger,lengthAsInteger)Dimwz()AsString={"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}ForiAsInteger=0ToUBound(wz)Dimresult=str+wz(i)Ifposition=length-1Orposition=UBound(wz)ThenConsole.WriteLine(result)ElsePrintString(result,position+1,length)EndIfNextEndSub
不用递归,写十层fornext其实也行