出題目的:
掌握任意數(shù)列之間的排序技巧
解題要求:
代碼通用、高效
盡量簡(jiǎn)潔
盡量不生成臨時(shí)文件
加分規(guī)則:
1 思路獨(dú)特基準(zhǔn)分5分
2 代碼高效、通用基準(zhǔn)分4分
3 技巧高超基準(zhǔn)分3分
4 代碼簡(jiǎn)潔基準(zhǔn)分2分
5 完美代碼加分15分
題目如下:
給出任意一組數(shù)列,正序輸出,如:
3 2008 11 19 777 23 2014 453 789 51
輸出為:3 11 19 23 51 453 777 789 2008 2014
說(shuō)明:
不必考慮特大數(shù),所給的數(shù)列中都是整數(shù)值。
dishuo:
復(fù)制代碼 代碼如下:
cls@echo offsetlocal 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]!
pausegoto: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-=1goto :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-=1goto 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-=1goto :eof
terse:
復(fù)制代碼 代碼如下:
@echo offsetlocal 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:
復(fù)制代碼 代碼如下:
@echo offsetlocal 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:
復(fù)制代碼 代碼如下:
@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)