当前位置:DOS资源站资料中心批处理教程 → 负数、超大数、重复数字排序

负数、超大数、重复数字排序

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-4-19 20:56:20

数字排序
a.txt  的内容


8
5
7
9
45
-200
34
2
0
32
3
12
3
-5
0
12
-5
12
45
-125
345
6
8
89
数字排序

@echo off&title DOS资源站 www.cmdos.net&setlocal EnableDelayedExpansion
::  by  小楼一夜听春雨 2007-11-25
::  可以对任何 200 位以内的整数进行排序。(包括负数、正数、0、及重复的数字)
::  缺点: 对于0开头的数字,结果会忽略首位的0
for /l %%a in (1 1 200) do set lin=0!lin!
for /f "delims=" %%a in (a.txt) do (
   set str=%%a
   if "!str:~0,1!"=="-" (set fus=a&set str=!str:~1!&set zf=_) else set zf=+
   set str=!lin!!str!
   set !zf!!str:~-200! !random!!random!!random!!random!!random!!random!!random!=a
)
if defined fus call :lis _ /r
call :lis +
pause&exit
:lis
   for /f "tokens=1,2 delims=_+= " %%a in ('set %1^|sort %2') do (
      for /f "tokens=* delims=0" %%i in ("%%a") do (
         if "%1"=="_" (set fuhao=-) else set fuhao=
         if "%%i"=="" (echo !fuhao!0) else echo !fuhao!%%i
))
goto :eof