方法1和方法2中,除了定义变量组外,还定义了一个序号变量(Gu1、Gu2),获取A、B的值,都可以通过循环这个序号变量完成,如果不去定义这个序号变量,还可以通过删除变量组中用过的变量来完成:
@echo off&setlocal enabledelayedexpansion
for %%a in (1 2) do set Xing%%a=0&set/p Han%%a=输入第 %%a 行字符:
for %%a in (%Han1%) do set/a Ye1+=1&set #!Ye1!=%%a
for %%a in (%Han2%) do set/a Ye2+=1&set @!Ye2!=%%a
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set #%%a=&set @%%a=
for %%a in (%Han1%) do (
set/a Gu1+=1,Gu2=0
for %%b in (%Han2%) do (
set/a Gu2+=1
if "%%a"=="%%b" if defined #!Gu1! if defined @!Gu2! set/a Xing2+=1&set #!Gu1!=&set @!Gu2!=
))
echo %Xing1%A%Xing2%B&pause&exit
@echo off&setlocal enabledelayedexpansion
for %%a in (1 2) do set Xing%%a=0&set/p Han%%a=输入第 %%a 行字符:
for %%a in (%Han1%) do set/a Ye1+=1&set #!Ye1!=%%a
for %%a in (%Han2%) do set/a Ye2+=1&set @!Ye2!=%%a
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set #%%a=&set @%%a=
call:Han %Han1%
echo %Xing1%A%Xing2%B&pause&exit
:Han
set/a Gu1+=1,Gu2=0
for %%a in (%Han2%) do (
set/a Gu2+=1
if "%%a"=="%1" if defined #!Gu1! if defined @!Gu2! set/a Xing2+=1&set #!Gu1!=&set @!Gu2!=
)
shift
if not "%1"=="" goto:Han
Last edited by Hanyeguxing on 2010-12-2 at 10:27 ]
In method 1 and method 2, in addition to defining the variable groups, an index variable (Gu1, Gu2) is also defined. The values of A and B can be obtained by looping through this index variable. If the index variable is not defined, it can also be done by deleting the used variables in the variable groups:
@echo off&setlocal enabledelayedexpansion
for %%a in (1 2) do set Xing%%a=0&set/p Han%%a=输入第 %%a 行字符:
for %%a in (%Han1%) do set/a Ye1+=1&set #!Ye1!=%%a
for %%a in (%Han2%) do set/a Ye2+=1&set @!Ye2!=%%a
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set #%%a=&set @%%a=
for %%a in (%Han1%) do (
set/a Gu1+=1,Gu2=0
for %%b in (%Han2%) do (
set/a Gu2+=1
if "%%a"=="%%b" if defined #!Gu1! if defined @!Gu2! set/a Xing2+=1&set #!Gu1!=&set @!Gu2!=
))
echo %Xing1%A%Xing2%B&pause&exit
@echo off&setlocal enabledelayedexpansion
for %%a in (1 2) do set Xing%%a=0&set/p Han%%a=输入第 %%a 行字符:
for %%a in (%Han1%) do set/a Ye1+=1&set #!Ye1!=%%a
for %%a in (%Han2%) do set/a Ye2+=1&set @!Ye2!=%%a
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set #%%a=&set @%%a=
call:Han %Han1%
echo %Xing1%A%Xing2%B&pause&exit
:Han
set/a Gu1+=1,Gu2=0
for %%a in (%Han2%) do (
set/a Gu2+=1
if "%%a"=="%1" if defined #!Gu1! if defined @!Gu2! set/a Xing2+=1&set #!Gu1!=&set @!Gu2!=
)
shift
if not "%1"=="" goto:Han
Last edited by Hanyeguxing on 2010-12-2 at 10:27 ]