0

我在这里有代码,但我不知道输入如何按降序排序的逻辑..

@echo off
:start1
cls
set /p num1=Enter #1:
if [%num1%]==[] goto error1
if %num1% LSS 0 goto a
if %num1% GTR 9 goto a


:start2
cls
set /p num2=Enter #2:
if [%num2%]==[] goto error2
if %num2% LSS 0 goto b
if %num2% GTR 9 goto b

:start3
cls
set /p num3=Enter #3:
if [%num3%]==[] goto error3
if %num3% LSS 0 goto c
if %num3% GTR 9 goto c

:start4
cls
set /p num4=Enter #4:
if [%num4%]==[] goto error4
if %num4% LSS 0 goto d
if %num4% GTR 9 goto d

:start5
cls
set /p num5=Enter #5:
if [%num5%]==[] goto error5
if %num5% LSS 0 goto e
if %num5% GTR 9 goto e

::Equations.........

::Error Trapping

:error1
echo No input!
pause
goto start1

:error2
echo No input!
pause
goto start2

:error3
echo No input!
pause
goto start3

:error4
echo No input!
pause
goto start4

:error5
echo No input!
pause
goto start5

:a
echo Input must be in the range of 0 to 9
pause
goto start1

:b
echo Input must be in the range of 0 to 9
pause
goto start2

:c
echo Input must be in the range of 0 to 9
pause
goto start3


:d
echo Input must be in the range of 0 to 9
pause
goto start4

:e
echo Input must be in the range of 0 to 9
pause
goto start5


:exit
pause
exit
4

1 回答 1

0

你可以试试这个:

@echo off &setlocal
for /f "delims==" %%a in ('set "$num" 2^>nul') do set "%%a="
:loop1
set /a count+=1
:loop2
set /p "$num%count%=Enter #%count%: "
call echo %%$num%count%%%|findstr /r "^[0-9]$" >nul|| (echo Error!&goto:loop2)
if %count% lss 5 goto:loop1
(for /f "tokens=2 delims==" %%a in ('set "$num"') do @echo %%a)|sort /r
于 2013-09-29T11:32:53.587 回答