返回列表 发帖
方法一、
@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 编辑 ]
技术问题请到论坛发帖求助!

TOP

再来一个,似乎更简洁。。
@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%%
  call set input=%%input:%%b=+%%b%%
)
set /a str=0%input%
echo.&echo 它们的总和是 %str%
echo.&pause&exitCOPY
技术问题请到论坛发帖求助!

TOP

返回列表