批处理如何遍历生成8位数全部数值?每位可选数字不同
如21113210,第1位和第6位有0,1,2三个数可选,第5位可选3,4,其他位可以选0,1。只找到多位二进制数的遍历方法,程序如下,会的参考下:[code]@Echo...
如21113210,第1位和第6位有0,1,2三个数可选,第5位可选3,4,其他位可以选0,1。
只找到多位二进制数的遍历方法,程序如下,会的参考下:
[code]
@Echo Off&SetLocal EnableDelayedExpansion
Set /P Num=请输入位数:
For /L %%I in (%Num%,-1,1) Do Set /A "Max+=1<<(%%I-1)"
(For /L %%I in (0,1,%Max%) Do (
Set /A a=%%I&set "Number="
For /L %%J in (1,1,%Num%) Do (
Set /A b=a%%2,a=a/2
Set "Number=!b!!Number!"
)
Echo !Number!
))>List.txt
Start List.txt
[/code] [/code] 展开
只找到多位二进制数的遍历方法,程序如下,会的参考下:
[code]
@Echo Off&SetLocal EnableDelayedExpansion
Set /P Num=请输入位数:
For /L %%I in (%Num%,-1,1) Do Set /A "Max+=1<<(%%I-1)"
(For /L %%I in (0,1,%Max%) Do (
Set /A a=%%I&set "Number="
For /L %%J in (1,1,%Num%) Do (
Set /A b=a%%2,a=a/2
Set "Number=!b!!Number!"
)
Echo !Number!
))>List.txt
Start List.txt
[/code] [/code] 展开
3个回答
展开全部
@echo off
for /f "tokens=1 delims=[]" %%1 in ('type %0^|find /n "=Start"')do set h=%%1
more +%h% %0>1.vbs
(for /f "delims=" %%1 in ('cscript //nologo "1.vbs"')do echo %%1)>list.txt
del 1.vbs
goto :eof
=Start
Dim Spt, Spl, Spm, CnNum, List, List1, List2, List3, List4, List5, List6, CoNum(), Count, CnStr, SoStr, SnStr
Randomize
Spt = "16-012,5-34,23478-01"
Do While List6 <> 17
CnNum = Empty
SnStr = Empty
Count = 0
For List = 0 To 17
CnNum = Empty
For List1 = 1 To 8
Spl = Split(Spt, ",")
For List2 = 0 To UBound(Spl)
Spm = Split(Spl(List2), "-")
For List3 = 1 To Len(Spm(0))
If CStr(List1) = CStr(Mid(Spm(0), List3, 1)) Then
CnNum = CnNum & Mid(Spm(1), Fix(Rnd * Len(Spm(1))) + 1, 1)
Exit For
End If
Next
Next
Next
ReDim Preserve CoNum(Count)
CoNum(Count) = CnNum
Count = Count + 1
Next
CnStr = Join(CoNum, vbCrLf)
SoStr = Split(CnStr, vbCrLf)
For List4 = 0 To UBound(SoStr)
For List5 = UBound(SoStr) To List4 + 1 Step -1
If Trim(SoStr(List4)) = Trim(SoStr(List5)) Then SoStr(List5) = Empty
Next
If Len(SoStr(List4)) > 0 Then SnStr = SnStr & SoStr(List4) & vbCrLf
Next
SnStr = Left(SnStr, Len(SnStr)-2)
List6 = UBound(Split(SnStr, vbCrLf))
Loop
Wscript.Echo SnStr
虽然是vbs写的,但还是满足你要用批处理的要求吧,以上代码保存为bat类型文件,注意不能直接右键复制,用ctrl+c复制
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
@echo off
set "bit1=0 1 2"
set "bit2=0 1"
set "bit3=0 1"
set "bit4=0 1"
set "bit5=3 4"
set "bit6=0 1 2"
set "bit7=0 1"
set "bit8=0 1"
for %%a in (%bit1%) do (
for %%b in (%bit2%) do (
for %%c in (%bit3%) do (
for %%d in (%bit4%) do (
for %%e in (%bit5%) do (
for %%f in (%bit6%) do (
for %%g in (%bit7%) do (
for %%h in (%bit7%) do (
echo %%a%%b%%c%%d%%e%%f%%g%%h
))))))))
pause
算不上多高明
追问
谢谢,代码非常直观,想法也很直接,很好。问一下如果想输出文本,>List.txt加在哪里?试过都不行,不是不输出就是少结果。
追答
@echo off
set "bit1=0 1 2"
set "bit2=0 1"
set "bit3=0 1"
set "bit4=0 1"
set "bit5=3 4"
set "bit6=0 1 2"
set "bit7=0 1"
set "bit8=0 1"
(for %%a in (%bit1%) do (
for %%b in (%bit2%) do (
for %%c in (%bit3%) do (
for %%d in (%bit4%) do (
for %%e in (%bit5%) do (
for %%f in (%bit6%) do (
for %%g in (%bit7%) do (
for %%h in (%bit7%) do (
echo %%a%%b%%c%%d%%e%%f%%g%%h
)))))))))>list.txt
pause
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
求逆战测试服安装程序 求好心人上传到网盘
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询