方法一、
| @echo off | | :main | | cls | | set /p input= | | echo %input%|findstr "^[a-zA-Z]*$">nul||goto main | | echo 你输入的是 %input% | | call :ie | | echo.&echo 它们的总和是 %str% | | echo.&pause&exit | | :ie | | set num=0 | | set var=%input:~0,1% | | for %%b in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do ( | | set /a num+=1 | | if /i "%var%"=="%%b" ( | | set /a str+=num | | call set input=%%input:~1%% | | call :ie | | ) | | ) | | goto :eofCOPY |
方法二、
| @echo off | | :main | | cls | | set /p input= | | echo %input%|findstr "^[a-zA-Z]*$">nul||goto main | | echo 你输入的是 %input% | | for %%b in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do ( | | set /a num+=1 | | call set %%b=%%num%% | | ) | | :ie | | set /a str+=%input:~0,1% | | set input=%input:~1% | | if defined input goto ie | | echo.&echo 它们的总和是 %str% | | echo.&pause&exitCOPY |
[ 本帖最后由 随风 于 2008-1-8 15:49 编辑 ] |