本帖最后由 wxyz0001 于 2019-10-30 12:46 编辑
求1-10数字,5个一组,每组数据不相同并>a.txt
输出后结果:
01,02,03,04,05
01,02,03,04,06
01,02,03,04,07
01,02,03,04,08
01,02,03,04,09
01,02,03,04,10
01,02,03,05,06
01,02,03,05,07
01,02,03,05,08
......
要求XP的批处理格式编写的代码
===============完美解决===================- @echo off&setlocal enabledelayedexpansion
- set " var=01 02 03 04 05 06 07 08 09 10"
- set "m=5"
- for %%i in (%var%) do (
- set /a n+=1&set #!n!=%%i
- if !n! leq !m! (set s=1!s!)else set s=!s!0
- )
- set/a r=n-m,i=j=1
- for /l %%i in (1,1,%r%) do set /a "i*=(n-%%i+1),j*=%%i"
- set s=0!s!&set /a "i/=j"
- (for /l %%i in (1 1 !i!) do (
- for /l %%j in (1 1 !n!) do (
- if "!s:~%%j,1!" == "1" set $=!$!,!#%%j!
- )
- for /f %%a in ("!s:10= !") do set "j=%%a"
- set s=0!j:0=!!j:1=!1!s:*10=!
- echo!$!&set "$="
- ))>$#.t
- sort $#.t /o a.txt
- del $#.t
- pause
复制代码 上面这段代码var字符数组可以根据需要设定没有规律的数字,是这段代码最大的优点
___________________________________- @echo off&setlocal enabledelayedexpansion
- set /a N=10,R=5,S=N-R,i=1,j=1
- for /l %%i in (1 1 %N%) do (
- if %%i lss 10 (set _%%i=0%%i) else set _%%i=%%i
- )
- for /l %%i in (1,1,%S%) do set /a "i*=(N-%%i+1),j*=%%i"
- set /a i/=j
- for /l %%i in (1 1 %R%) do set /a A%%i=%%i,B%%i=%%i+S&set #=!#!,!_%%i!
- echo!#!
- for /l %%a in (2 1 !I!) do (
- set "#="
- for /l %%i in (1 1 !R!) do if not #!A%%i! == #!B%%i! set M=%%i
- for %%i in (!M!) do (
- set L=!A%%i!
- for /l %%j in (1 1 %R%) do (
- if %%j geq %%i set/a A%%j=L+1,L=A%%j
- set #=!#! !A%%j!
- )
- )
- for %%i in (!#!) do set emp=!emp!,!_%%i!
- echo!emp!&set emp=
- )>>a.txt
- echo 总 !i! 组
- pause
复制代码
|