圆月山庄资源网 Design By www.vgjia.com
出题目的:
掌握任意数列之间的排序技巧
解题要求:
代码通用、高效
尽量简洁
尽量不生成临时文件
加分规则:
1 思路独特基准分5分
2 代码高效、通用基准分4分
3 技巧高超基准分3分
4 代码简洁基准分2分
5 完美代码加分15分
题目如下:
给出任意一组数列,正序输出,如:
3 2008 11 19 777 23 2014 453 789 51
输出为:3 11 19 23 51 453 777 789 2008 2014
说明:
不必考虑特大数,所给的数列中都是整数值。
dishuo:
复制代码 代码如下:
cls&@echo off&setlocal enabledelayedexpansion
set "strings=3 2008 11 19 777 23 2014 453 789 51"
echo %strings%
set/a n=0
for %%i in (%strings%) do (
set/a n+=1
set num[!n!]=%%i
)
call :quicksort num 1 %n%
for /l %%i in (1,1,%n%) do echo !num[%%i]!
pause&goto:eof
:QuickSort
::code by dishuostec
::use call :quicksort arrary low high
set "ARR=%1"
set/a dep=0
call :QS %2 %3
goto:eof
:QS
set/a dep+=1,lTmpLow=%1,lTmpHi=%2,Low=%1,Hi=%2
if %Hi% leq %Low% set/a dep-=1&goto :eof
set/a lTmpMid=(Low+Hi)/2
call set/a vTempVal=%%%ARR%[!lTmpMid!]%%
:qsMainLoop
if !lTmpLow! leq !lTmpHi! (
:qsLoop1
call set/a vVal=%%%ARR%[!lTmpLow!]%%
if !vVal! lss !vTempVal! if !lTmpLow! lss !Hi! set/a lTmpLow+=1& goto qsLoop1
:qsLoop2
call set/a vVal=%%%ARR%[!lTmpHi!]%%
if !vTempVal! lss !vVal! if !Low! lss !lTmpHi! set/a lTmpHi-=1&goto qsLoop2
:qsSwap
if !lTmpLow! leq !lTmpHi! (
call set/a vTmpHold=%%%ARR%[!lTmpLow!]%%
call set/a %ARR%[!lTmpLow!]=%%%ARR%[!lTmpHi!]%%
set/a %ARR%[!lTmpHi!]=vTmpHold
set/a lTmpLow+=1,lTmpHi-=1
)
goto qsMainLoop
)
set/a lTmpLow[%dep%]=lTmpLow,Hi[%dep%]=Hi
if %Low% lss %lTmpHi% call :QS %Low% %lTmpHi%
call set lTmpLow=%%lTmpLow[!dep!]%%&call set Hi=%%Hi[!dep!]%%
if %lTmpLow% lss %Hi% call :QS %lTmpLow% %Hi%
set/a dep-=1&goto :eof

 
 
terse:
复制代码 代码如下:
@echo off&setlocal enabledelayedexpansion
set str=3 2008 11 19 777 23 2014 453 789 51
for %%i in (%str%) do (
set str=0000000000%%i
set .!str:~-10! !random!=%%i
)
for /f "tokens=2 delims==" %%i in ('set .') do set/p=%%i <nul
pause>nul

 
 
MKL:
复制代码 代码如下:
@echo off&setlocal enabledelayedexpansion
set "p=3 2008 11 19 777 23 2014 453 789 51"
for %%i in (%p%) do (
set t=1
for %%r in (%p%) do (
if %%i gtr %%r set /a t=!t!+1
)
set !t!=%%i
)
echo !1! !2! !3! !4! !5! !6! !7! !8! !9! !10!
pause

 
523066680:
复制代码 代码如下:
@echo off
setlocal enabledelayedexpansion
set hang=3 2008 11 19 777 23 2014 453 789 51 3 3 4 2014
set n=0
for %%a in (%hang%) do (
set /a num=1,n+=1
for %%b in (%hang%) do (
if %%a gtr %%b set /a num+=1
)
call :next !num!
set !num!=%%a
)
for /l %%a in (1,1,%n%) do echo !%%a!
pause
goto :eof
:next
if defined %num% (set /a num+=1 &goto :next)
标签:
数值排序

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com