- @echo off & setlocal enabledelayedexpansion
- for /f "delims=" %%a in (a.txt) do (
- for %%b in (%%a) do (
- call :p %%b
- )
- )
- for /l %%i in (0,1,9) do (
- if defined f%%i (
- call :sortstr str%%i newstr
- echo !newstr!
- )
- )
- pause
- goto :eof
-
-
-
- :p
- set s=%1
- for /l %%i in (0,1,9) do (
- if "!s:~-1!"=="%%i" (
- if not defined f%%i2 set f%%i2=1&set str%%i=%%i
- set str%%i=!str%%i! %%b
- if not defined f%%i set f%%i=1
- goto :eof
- )
- )
- goto :eof
-
- :sortstr
- setlocal
- for %%a in (!%1!) do (
- set/ajj+=1
- set s!jj!=%%a
- )
- call :sort s %jj%
- for /l %%a in (1,1,%jj%) do (
- set ss=!ss! !s%%a!
- )
- endlocal&set %2=%ss%&goto :eof
-
- :sort arrname %ubound%
- set a=%1&set u=%2&set i=2
- :sort_1
- if %i% gtr %u% goto :eof
- set /a %a%0=%a%%i%,j=i-1
- :sort_2
- if !%a%0! lss !%a%%j%! (
- set /a k=j+1
- set /a %a%!k!=%a%%j%,j-=1
- goto sort_2
- )
- set /a k=j+1
- set /a %a%%k%=%a%0,i+=1
- goto sort_1
复制代码
|