[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[数值计算] 数字矩阵随机黑洞

写下这段代码主要目的是让大家都了解下数值计算的相关技巧:
  1. @echo off
  2. :begin
  3. setlocal enabledelayedexpansion
  4. cls&set "code= xy"
  5. :again
  6. set /a a=%random%%%7+2,b=%random%%%7+2,c=a-b
  7. if %c:~-1% leq 1 goto again
  8. set /a n+=1
  9. if "%c:~,1%" equ "-" (
  10.    set "!code:~%n%,1!min=%a%"&set "!code:~%n%,1!max=%b%"
  11.    ) else (
  12.    set "!code:~%n%,1!max=%a%"&set "!code:~%n%,1!min=%b%"
  13. )
  14. if %n% neq 2 goto again
  15. for /l %%a in (%xmin%,1,%xmax%) do (
  16.     for /l %%i in (%ymin%,1,%ymax%) do set "_%%a%%i=a"
  17. )
  18. for /l %%a in (1,1,9) do (
  19.     for /l %%i in (1,1,9) do (
  20.         set /a num+=1
  21.         if !num! lss 10 set "num= !num!"
  22.         if not defined _%%a%%i (
  23.            set /p=!num! <nul
  24.            ) else (
  25.            set /p=   <nul
  26.         )
  27.     )
  28.     echo.
  29. )  
  30. ping /n 2 127.1>nul&endlocal&goto begin
复制代码

[ 本帖最后由 batman 于 2008-8-28 22:53 编辑 ]
1

评分人数

***共同提高***

画圆玩儿

  1. @echo off & setlocal EnableDelayedExpansion
  2.         mode con:cols=100 lines=100
  3. echo.
  4. echo 利用批处理绘制圆形,BETA 1.00 版。2008年8月10日编译完成。
  5. echo.
  6. echo ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  7.         set "DrawPoint=○"
  8.         set "Radius=19"
  9.         set /a "Square=%Radius%*%Radius%"
  10.         set /a "Diameter=%Radius%*2"
  11.         set "Interval=  "
  12.         set /a "y=%Diameter%"
  13.         set /a "x=0"
  14.         set /a "ADD=15"
  15.         set /a "Area1=%Square%+%ADD%"
  16.         set /a "Area2=%Square%-%ADD%"
  17.         for /l %%i in (%Diameter%,-1,0) do Call :Draw_Point "%%i"
  18.         goto :End
  19. :Draw_Point _y_
  20.         set "Line=┃"
  21.         for /l %%i in (0,1,%Diameter%) do (
  22.                 call :Compute_Deuce_Length "%%i" "%1"
  23.                 call :Draw_Line "!CResult!"
  24.                 )
  25.         echo %Line%┃
  26.         goto :EOF
  27. :Draw_Line _rst_
  28.         set "res=%~1"
  29.         if '%res% LSS %Area2%' (
  30.                 set "Line=%Line%%Interval%"
  31.                 goto :EOF
  32.                 )
  33.         if '%res% GTR %Area1%' (
  34.                 set "Line=%Line%%Interval%"
  35.                 goto :EOF
  36.                 )
  37.         set "Line=%Line%%DrawPoint%"
  38.         goto :EOF
  39. :Compute_Deuce_Length _x_ _y_
  40.         set "Cx=%~1"
  41.         set "Cy=%~2"
  42.         if "%Cx%" LEQ "%Radius%" (
  43.                 set /a "Factor1=%Radius%-%Cx%"
  44.                 ) else (
  45.                 set /a "Factor1=%Cx%-%Radius%"
  46.                 )
  47.         if "%Cy%" LEQ "%Radius%" (
  48.                 set /a "Factor2=%Radius%-%Cy%"
  49.                 ) else (
  50.                 set /a "Factor2=%Cy%-%Radius%"
  51.                 )
  52.         set /a "Factor1=%Factor1%*%Factor1%"
  53.         set /a "Factor2=%Factor2%*%Factor2%"
  54.         set /a "CResult=%Factor1%+%Factor2%"
  55.         goto :EOF
  56. :End
  57. echo ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
  58. echo.
  59. echo 本演示由 Flyinspace 发表于 http://www.cn-dos.net/forum ,转载请注明.
  60. pause>nul
复制代码

[ 本帖最后由 pusofalse 于 2008-8-29 00:16 编辑 ]

TOP

效率上存在问题,感觉还可简洁点。。。
***共同提高***

TOP

返回列表