Board logo

标题: 【出题】批处理逐字输出效果练习 [打印本页]

作者: plp626    时间: 2011-8-14 12:48     标题: 【出题】批处理逐字输出效果练习

  1. THEY CAME FIRST for the Coummunists,
  2.      and I didn't speak up because I wasn' t a Communist.
  3. THEN THEY CAME for the Jews,
  4.      and I didn't speak up because I wasn' t a Jew.
  5. THEN THEY CAME for the trade unionists,
  6.      and I didn't speak up because I wasn' t a trade unionist.
  7. THEN THEY CAME for the Catholics,
  8.      and I didn't speak up because I was a Protestant.
  9. THEN THEY CAME for me,
  10.      and by that time no one was left to speak up.
  11.                                      Pastor Martin Niemoeller
复制代码
显示速度每分钟200字母;代码尽量短小简洁;(注意文字内有很多重复短语)
作者: CrLf    时间: 2011-8-14 13:02

这里的字是指单词还是字母呢?
作者: plp626    时间: 2011-8-14 13:10

逐字母显示,就像键盘敲代码的效果。。。
作者: lfoqtal    时间: 2011-8-14 14:40

本帖最后由 lfoqtal 于 2011-8-14 14:43 编辑

吃螃蟹呀!
自认为不够精简,输出时间还行啦(包括空格的速度)
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "skip=16 delims=" %%a in (%0) do (
  3.       call :1 "%%a"
  4.       set b=0&echo.
  5.      )
  6. pause<nul
  7. goto :eof
  8. :1
  9. set "a=%~1"
  10. :2
  11. if "!a:~%b%,1!"=="" goto :eof
  12. set/p=!a:~%b%,1!<nul
  13. set /a b+=1
  14. for /l %%i in (1,1,100) do a 2>nul
  15. goto :2
  16. THEY CAME FIRST for the Coummunists,
  17.      and I didn't speak up because I wasn' t a Communist.
  18. THEN THEY CAME for the Jews,
  19.      and I didn't speak up because I wasn' t a Jew.
  20. THEN THEY CAME for the trade unionists,
  21.      and I didn't speak up because I wasn' t a trade unionist.
  22. THEN THEY CAME for the Catholics,
  23.      and I didn't speak up because I was a Protestant.
  24. THEN THEY CAME for me,
  25.      and by that time no one was left to speak up.
  26.                                      Pastor Martin Niemoeller
复制代码

作者: 545810831    时间: 2011-8-14 17:39

我试一下,做到了分行输出,就是字符之间有空隔,不知谁帮我改一下。
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "delims=" %%i in (1.txt) do (
  4. set b=%%i
  5. for /l %%a in (0 1 100) do (
  6. set/p var=!var!!b:~%%a,1!<nul&set var=  
  7. for /l %%b in (0 1 300) do echo %%b>nul
  8. )
  9. )
  10. pause
复制代码

作者: 风之语故乡    时间: 2011-8-16 20:49

回复 4# lfoqtal


    win7 下,你的代码空格不显示。
关于我的:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "skip=37 delims=" %%i in ('findstr /n .* %0') do (
  4. set "Mstr=%%i"
  5. set "Mstr=!Mstr:*:=!"
  6. call :逐字显示
  7. echo.
  8. )
  9. pause>nul
  10. :逐字显示
  11. call :FunDelay 200
  12. if defined Mstr (
  13. set "s=!Mstr:~0,1!"
  14. if defined s (
  15. set /p "=@!s!"<nul
  16. set Mstr=!Mstr:~1!
  17. goto 逐字显示
  18. )
  19. ) else (
  20. set /p "="<nul
  21. )
  22. goto :eof
  23. :FunDelay
  24. set beginTime=%time%
  25. set/a minute1=1%beginTime:~3,2%-100
  26. set/a second1=1%beginTime:~6,2%%beginTime:~-2%0-100000
  27. :LoopContinue
  28. set nowTime=%time%
  29. set/a minute2=1%nowTime:~3,2%-100
  30. set/a second2=1%nowTime:~6,2%%nowTime:~-2%0-100000
  31. set/a difMs=((%minute2%-%minute1%+60)%%60)*60000+%second2%-%second1%
  32. if %difMs% lss %1 goto LoopContinue
  33. goto :eof
  34. THEY CAME FIRST for the Coummunists,
  35.      and I didn't speak up because I wasn' t a Communist.
  36. THEN THEY CAME for the Jews,
  37.      and I didn't speak up because I wasn' t a Jew.
  38. THEN THEY CAME for the trade unionists,
  39.      and I didn't speak up because I wasn' t a trade unionist.
  40. THEN THEY CAME for the Catholics,
  41.      and I didn't speak up because I was a Protestant.
  42. THEN THEY CAME for me,
  43.      and by that time no one was left to speak up.
  44.                                      Pastor Martin Niemoeller
复制代码
精简肯定是谈不上了,
还有那个延时函数,挺庞大的




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2