China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 12:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Numerical comparison View 3,185 Replies 19
Floor 16 Posted 2010-12-01 20:28 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Borrowing the idea from the upstairs
@echo off&setlocal enabledelayedexpansion
for %%a in (1 2) do (
set/p $%%a=Input group %%a:
set n=0
for %%b in (!$%%a!) do (set /a n+=1&set $%%a-%%b=1&set $%%a-%%b-!n!=1)
)
set/a n=0,$a=0,$b=0
for %%a in (%$1%) do (
set /a n+=1
if defined $2-%%a-!n! set /a $a+=1&set $2-%%a=
if defined $2-%%a set /a $b+=1
)
echo %$a%A%$b%B
pause


There are really many issues to consider, the following is okay:

@echo off
:lp
endlocal&setlocal enabledelayedexpansion
for %%a in (1 2) do (
set/p $%%a=Input group %%a:
set n=0
for %%b in (!$%%a!) do (set /a n+=1&set/a $%%a.%%b +=1&set $%%a.%%b.!n!=1)
)
set/a n=0,$a=0,$b=0
for %%a in (%$1%) do (
set /a n+=1
if defined $2.%%a.!n! (set /a $a+=1,$2.%%a -=1) else set st=!st! %%a
)
for %%a in (%st%) do if !$2.%%a! gtr 0 set /a $b+=1,$2.%%a -=1

echo %$a%A%$b%B&echo;&echo;&goto :lp


[ Last edited by netbenton on 2010-12-1 at 01:28 ]
精简
=> 个人网志
Floor 17 Posted 2010-12-01 22:51 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
In method 1 and method 2, you can change
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set Gu1=!Gu1:%%a =!
to
for %%a in (%Gu1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set Gu1=!Gu1:%%a =!


[ Last edited by Hanyeguxing on 2010-12-2 at 09:52 ]
Floor 18 Posted 2010-12-02 04:07 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
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 ]
Floor 19 Posted 2010-12-02 04:36 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
The methods 2, 3, and 4 of Hanyeguxing have incorrect test results for the following combination:

1 1 2 2 1 1 1
2 1 2 1 1 1 2
精简
=> 个人网志
Floor 20 Posted 2010-12-02 09:18 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Originally posted by netbenton at 2010-12-2 04:36:
For the combination below, the results of methods 2, 3, and 4 of Hanyeguxing are incorrect:

1 1 2 2 1 1 1
2 1 2 1 1 1 2

Actually, methods 1 and 2 are fine, but methods 3 and 4 are incorrect.
The reason is that the design ideas of methods 3 and 4 are flawed because whether to preferentially obtain all the values of A may result in different outcomes.
Well, it's embarrassing. It has been modified...

[ Last edited by Hanyeguxing on 2010-12-2 at 10:16 ]
Forum Jump: