递归法(效率一般)- @echo off&setlocal enabledelayedexpansion
- for /l %%a in (1,1,500) do set "str=!str! !random!-%%a"
- echo !str!
- for /l %%a in (1,1,250) do (
- for %%a in (!str!) do (
- for /f "tokens=1,2 delims=-" %%b in ("%%a") do (
- for %%d in (max min) do (
- if not defined %%d (
- set /a %%d=%%b
- ) else (
- if %%d equ max if %%b gtr !%%d! set /a %%d=%%b
- if %%d equ min if %%b lss !%%d! set /a %%d=%%b
- )
- )
- )
- )
- for %%a in (max min) do (
- for %%b in (!str!) do (
- for /f "tokens=1,2 delims=-" %%c in ("%%b") do (
- if %%c equ !%%a! (
- set "str=!str: %%b=!"
- if %%a equ max set "_%%a=%%c !_%%a!"
- if %%a equ min set "_%%a=!_%%a! %%c"
-
- )
- )
- )
- set "%%a="
- )
- )
- echo %_min:~1% %_max:~1%
- pause>nul
复制代码
|