|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
『楼 主』:
数值比较
使用 LLM 解释/回答一下
今天看到一个题目,放到论坛大家写写,呵呵!
从命令行输入两行字符串,字符串符合如下格式
1 1 3 5
5 3 2 1
全部由0-9十个数字组成,每个数字都是单数,且中间用空格隔开,我们把第一组输入
的表示为A,第二组的表示为B,判定A,B的每个对应位有几个相同。如下数字:
==============
1 2 3 5
1 1 5 5
==============
其中对应为相同的有两组,分别为(1,1)和(5,5).表示为2A,如果仅有一组相同的表
示1A,三组相同表示3A,以此类推。
比较完A类型(对应为相同)后,再判定剩下的A和B,是否有相同的数字,有一组算1B,
两组算2B,不要重复比较,以此类推 上面的结果则为 2A0B.以下为类:
==================
1 1 2 2
2 2 1 1
0A4B
==================
1 3 3 3
3 1 1 1
0A2B
==================
1 2 3 4
4 3 2 1
0A4B
==================
1 1 1 1
1 1 1 1
4A0B
==================
1 3 5 6
2 3 5 9
2A0B
==================
只要输出结果nAmB
Today I saw a problem, put it on the forum for everyone to write, hehe!
Input two lines of strings from the command line, the strings conform to the following format
1 1 3 5
5 3 2 1
All are composed of ten digits from 0-9, each digit is odd, and separated by spaces in the middle. We represent the first group of input as A, the second group as B, and determine how many are the same in each corresponding bit of A and B. The following numbers:
==============
1 2 3 5
1 1 5 5
==============
Among them, there are two groups of correspondences that are the same, namely (1,1) and (5,5). Expressed as 2A, if there is only one group of the same, it is expressed as 1A, three groups of the same are expressed as 3A, and so on.
After comparing the A type (corresponding to the same), then determine whether there are the same numbers in the remaining A and B. One group counts as 1B, two groups count as 2B, and do not compare repeatedly, and so on. The above result is 2A0B. The following are examples:
==================
1 1 2 2
2 2 1 1
0A4B
==================
1 3 3 3
3 1 1 1
0A2B
==================
1 2 3 4
4 3 2 1
0A4B
==================
1 1 1 1
1 1 1 1
4A0B
==================
1 3 5 6
2 3 5 9
2A0B
==================
Just output the result nAmB
|

http://www.godule.com |
|
2010-11-11 16:15 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
怎么就没人写呢?要是搁以前一帮人摞代码,我将我写的垃圾代码贴出来,
@echo off&setlocal enabledelayedexpansion&color 3e
set /p aa=输入一行字符:
set /p bb=输入一行字符:
set n=0
set m=0
:loopa
set i=0&set j=0&set k=0&set l=0&set ii=0
for %%i in (!aa!) do (
set /a i+=1
set /a k=ii+2
for %%h in (!bb!) do (
set /a j+=1
if "!i!"=="!j!" (if "%%i"=="%%h" (
call,set aa=%%aa:~,!ii!%%%%aa:~!k!%%
call,set bb=%%bb:~,!ii!%%%%bb:~!k!%%
set /a n+=1
goto :loopa
)
)
)
set /a ii+=2
set j=0
)
echo.
echo.剔除A类型以后的值:%aa%============%bb%
echo.
echo.
echo.
echo.记录B类型数值的变化过程如下:
:loopb
set i=0&set j=0&set k=0&set l=0
for %%i in (!aa!) do (
set /a k=i+2
for %%h in (!bb!) do (
set /a l=j+2
if /i "%%i"=="%%h" (
call,set aa=%%aa:~,!i!%%%%aa:~!k!%%
call,set bb=%%bb:~,!j!%%%%bb:~!l!%%
set /a m+=1
echo.第!m!次的结果 !aa!==================!bb!
goto:loopb
)
set /a j+=2
)
set /a i+=2
set /a j=0
)
echo.
echo.
echo.
echo.最终的结果统计
echo.%n%A%m%B
pause
Why is there no one writing it? If it were before, a group of people would stack code. I would post my garbage code.
@echo off&setlocal enabledelayedexpansion&color 3e
set /p aa=Enter a line of characters:
set /p bb=Enter a line of characters:
set n=0
set m=0
:loopa
set i=0&set j=0&set k=0&set l=0&set ii=0
for %%i in (!aa!) do (
set /a i+=1
set /a k=ii+2
for %%h in (!bb!) do (
set /a j+=1
if "!i!"=="!j!" (if "%%i"=="%%h" (
call,set aa=%%aa:~,!ii!%%%%aa:~!k!%%
call,set bb=%%bb:~,!ii!%%%%bb:~!k!%%
set /a n+=1
goto :loopa
)
)
)
set /a ii+=2
set j=0
)
echo.
echo.The value after removing type A:%aa%============%bb%
echo.
echo.
echo.
echo.The process of changing the value of type B is as follows:
:loopb
set i=0&set j=0&set k=0&set l=0
for %%i in (!aa!) do (
set /a k=i+2
for %%h in (!bb!) do (
set /a l=j+2
if /i "%%i"=="%%h" (
call,set aa=%%aa:~,!i!%%%%aa:~!k!%%
call,set bb=%%bb:~,!j!%%%%bb:~!l!%%
set /a m+=1
echo.The result of the !m!th time !aa!==================!bb!
goto:loopb
)
set /a j+=2
)
set /a i+=2
set /a j=0
)
echo.
echo.
echo.
echo.Final result statistics
echo.%n%A%m%B
pause
|

http://www.godule.com |
|
2010-11-13 12:15 |
|
|
zhoupeng243
新手上路

积分 13
发帖 15
注册 2010-9-18
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal enabledelayedexpansion
color 0b
set /p aa=输入A行字符:
set /p bb=输入B行字符:
set n=0
set m=0
for /f "tokens=1,2,3,4* delims= " %%a in ("%aa%") do (
for /f "tokens=1,2,3,4* delims= " %%i in ("%bb%") do (
set a=%%a & set b=%%b & set c=%%c & set d=%%d
set i=%%i & set j=%%j & set k=%%k & set l=%%l
if "!a!"=="!i!" (set /a n+=1)&(set a=a)&(set i=i)
if "!b!"=="!j!" (set /a n+=1)&(set b=b)&(set j=j)
if "!c!"=="!k!" (set /a n+=1)&(set c=c)&(set k=k)
if "!d!"=="!l!" (set /a n+=1)&(set d=d)&(set l=l)
if "!a!"=="!j!" (set /a m+=1)&(set a=a)&(set j=j)
if "!a!"=="!k!" (set /a m+=1)&(set a=a)&(set k=k)
if "!a!"=="!l!" (set /a m+=1)&(set a=a)&(set l=l)
if "!b!"=="!i!" (set /a m+=1)&(set b=b)&(set i=i)
if "!b!"=="!k!" (set /a m+=1)&(set b=b)&(set k=k)
if "!b!"=="!l!" (set /a m+=1)&(set b=b)&(set l=l)
if "!c!"=="!i!" (set /a m+=1)&(set c=c)&(set i=i)
if "!c!"=="!j!" (set /a m+=1)&(set c=c)&(set j=j)
if "!c!"=="!l!" (set /a m+=1)&(set c=c)&(set l=l)
if "!d!"=="!i!" (set /a m+=1)&(set d=d)&(set i=i)
if "!d!"=="!j!" (set /a m+=1)&(set d=d)&(set j=j)
if "!d!"=="!k!" (set /a m+=1)&(set d=d)&(set k=k)
)
)
echo.
echo.
echo.
echo.最终的结果统计
echo.%n%A%m%B
pause
@echo off
setlocal enabledelayedexpansion
color 0b
set /p aa=Enter line A characters:
set /p bb=Enter line B characters:
set n=0
set m=0
for /f "tokens=1,2,3,4* delims= " %%a in ("%aa%") do (
for /f "tokens=1,2,3,4* delims= " %%i in ("%bb%") do (
set a=%%a & set b=%%b & set c=%%c & set d=%%d
set i=%%i & set j=%%j & set k=%%k & set l=%%l
if "!a!"=="!i!" (set /a n+=1)&(set a=a)&(set i=i)
if "!b!"=="!j!" (set /a n+=1)&(set b=b)&(set j=j)
if "!c!"=="!k!" (set /a n+=1)&(set c=c)&(set k=k)
if "!d!"=="!l!" (set /a n+=1)&(set d=d)&(set l=l)
if "!a!"=="!j!" (set /a m+=1)&(set a=a)&(set j=j)
if "!a!"=="!k!" (set /a m+=1)&(set a=a)&(set k=k)
if "!a!"=="!l!" (set /a m+=1)&(set a=a)&(set l=l)
if "!b!"=="!i!" (set /a m+=1)&(set b=b)&(set i=i)
if "!b!"=="!k!" (set /a m+=1)&(set b=b)&(set k=k)
if "!b!"=="!l!" (set /a m+=1)&(set b=b)&(set l=l)
if "!c!"=="!i!" (set /a m+=1)&(set c=c)&(set i=i)
if "!c!"=="!j!" (set /a m+=1)&(set c=c)&(set j=j)
if "!c!"=="!l!" (set /a m+=1)&(set c=c)&(set l=l)
if "!d!"=="!i!" (set /a m+=1)&(set d=d)&(set i=i)
if "!d!"=="!j!" (set /a m+=1)&(set d=d)&(set j=j)
if "!d!"=="!k!" (set /a m+=1)&(set d=d)&(set k=k)
)
)
echo.
echo.
echo.
echo.Final result statistics
echo.%n%A%m%B
pause
|
|
2010-11-13 12:59 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
楼上的不对啊,如果A:1 1 2 2 B:2 2 1 1 答案应该是0A4B,而你的却是0A2B
The answer upstairs is incorrect. If A:1 1 2 2 and B:2 2 1 1, the answer should be 0A4B, but yours is 0A2B
|

http://www.godule.com |
|
2010-11-13 13:08 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我看了,表示没看懂。
是不是这样子:
1 1 2 2
2 2 1 1
0A4B
先进行竖向的比较,有4列 ,都是不同的,所以得到 0A
然后进行两行之间进行比较,可以匹配4组相同的(不重复匹配).所以0A4B
1 2 3 4
4 3 2 1
0A4B
这个是这种情况,然后下面那个不同了
1 1 1 1
1 1 1 1
4A0B
为什么是0B哇 ,晕掉了
============================
哦知道了, 就是A是按列对比的。
剩下的数字可以交错判断,1111这个是全都被A吞掉了
Last edited by 523066680 on 2010-11-13 at 22:10 ]
I saw it and said I didn't understand.
Is it like this:
1 1 2 2
2 2 1 1
0A4B
First, compare vertically, there are 4 columns, all different, so get 0A
Then compare between the two lines, and 4 groups of the same can be matched (non - repeated matching). So 0A4B
1 2 3 4
4 3 2 1
0A4B
This is this situation, and then the following is different
1 1 1 1
1 1 1 1
4A0B
Why is it 0B? Oh, I get it. That is, A is compared by columns.
The remaining numbers can be judged interlaced. For 1111, this is all swallowed by A
|

综合型编程论坛
我的作品索引 |
|
2010-11-13 22:02 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
|
2010-11-13 22:15 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
胖胖的,而且没有写用户输入部分
@echo off
setlocal enabledelayedexpansion
set numa=1134
set numb=3364
set /a sameA=0,sameB=0
for /l %%a in (0,1,3) do (
echo !numa:~%%a,1! - !numb:~%%a,1!
if "!numa:~%%a,1!"=="!numb:~%%a,1!" (
set /a sameA+=1,cut=%%a+1
for %%n in (!cut!) do (
set numa=!numa:~0,%%a!x!numa:~%%n!
set numb=!numb:~0,%%a!x!numb:~%%n!
)
)
)
set /a num_n=8-sameA*2-1,x=0
set next=%numa:x=%%numb:x=%
:lp
set /a xb=x+1
for /l %%a in (%xb%,1,%num_n%) do (
if "!next:~%%a,1!"=="!next:~%x%,1!" (
set /a sameB+=1
set next=!next:~0,%x%!x!next:~%xb%!
set tmpstr=!next:~%%a!
set next=!next:~0,%%a!x!tmpstr:~1!
goto :break
)
)
:break
if %x% lss %num_n% (set /a x+=1 &goto :lp)
echo %sameA%A%sameB%B
pause
1 - 3
1 - 3
3 - 6
4 - 4
1A2B
Last edited by 523066680 on 2010-11-13 at 23:54 ]
Fat and there is no part where the user input is written
@echo off
setlocal enabledelayedexpansion
set numa=1134
set numb=3364
set /a sameA=0,sameB=0
for /l %%a in (0,1,3) do (
echo !numa:~%%a,1! - !numb:~%%a,1!
if "!numa:~%%a,1!"=="!numb:~%%a,1!" (
set /a sameA+=1,cut=%%a+1
for %%n in (!cut!) do (
set numa=!numa:~0,%%a!x!numa:~%%n!
set numb=!numb:~0,%%a!x!numb:~%%n!
)
)
)
set /a num_n=8-sameA*2-1,x=0
set next=%numa:x=%%numb:x=%
:lp
set /a xb=x+1
for /l %%a in (%xb%,1,%num_n%) do (
if "!next:~%%a,1!"=="!next:~%x%,1!" (
set /a sameB+=1
set next=!next:~0,%x%!x!next:~%xb%!
set tmpstr=!next:~%%a!
set next=!next:~0,%%a!x!tmpstr:~1!
goto :break
)
)
:break
if %x% lss %num_n% (set /a x+=1 &goto :lp)
echo %sameA%A%sameB%B
pause
1 - 3
1 - 3
3 - 6
4 - 4
1A2B
Last edited by 523066680 on 2010-11-13 at 23:54 ]
|

综合型编程论坛
我的作品索引 |
|
2010-11-13 23:17 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
我还是不折腾了……
为什么例子中
1 3 3 3
3 1 1 1
0A2B
===========
不能分 11 11 33 33 咩,剔除的时候是全部相同都剔除吗
Last edited by 523066680 on 2010-11-13 at 23:27 ]
I still won't mess around...
Why in the example
1 3 3 3
3 1 1 1
0A2B
===========
Can't be divided into 11 11 33 33, right? When removing, is it that all the same are removed?
Last edited by 523066680 on 2010-11-13 at 23:27 ]
|

综合型编程论坛
我的作品索引 |
|
2010-11-13 23:26 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
|
2010-11-13 23:47 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
应该可以了
@echo off
setlocal enabledelayedexpansion
set numa=1333
set numb=3111
set /a sameA=0,sameB=0
for /l %%a in (0,1,3) do (
echo !numa:~%%a,1! - !numb:~%%a,1!
if "!numa:~%%a,1!"=="!numb:~%%a,1!" (
set /a sameA+=1,cut=%%a+1
for %%n in (!cut!) do (
set numa=!numa:~0,%%a!x!numa:~%%n!
set numb=!numb:~0,%%a!x!numb:~%%n!
)
)
)
set /a num_n=8-sameA*2,x=0
set next=%numa:x=%%numb:x=%AAA
for /l %%a in (0,1,9) do (
set tmpstr=!next:%%a=!
set tmpstr=!tmpstr:~0,%num_n%!
if not "!tmpstr:AA=!"=="!tmpstr!" (set /a sameB+=1)
)
echo %sameA%A%sameB%B
pause
1 - 3
3 - 1
3 - 1
3 - 1
0A2B
It should be okay
@echo off
setlocal enabledelayedexpansion
set numa=1333
set numb=3111
set /a sameA=0,sameB=0
for /l %%a in (0,1,3) do (
echo !numa:~%%a,1! - !numb:~%%a,1!
if "!numa:~%%a,1!"=="!numb:~%%a,1!" (
set /a sameA+=1,cut=%%a+1
for %%n in (!cut!) do (
set numa=!numa:~0,%%a!x!numa:~%%n!
set numb=!numb:~0,%%a!x!numb:~%%n!
)
)
)
set /a num_n=8-sameA*2,x=0
set next=%numa:x=%%numb:x=%AAA
for /l %%a in (0,1,9) do (
set tmpstr=!next:%%a=!
set tmpstr=!tmpstr:~0,%num_n%!
if not "!tmpstr:AA=!"=="!tmpstr!" (set /a sameB+=1)
)
echo %sameA%A%sameB%B
pause
1 - 3
3 - 1
3 - 1
3 - 1
0A2B
|

综合型编程论坛
我的作品索引 |
|
2010-11-13 23:56 |
|
|
huahua0919
银牌会员
    
积分 1608
发帖 780
注册 2007-10-7
状态 离线
|
|
2010-11-14 00:05 |
|
|
523066680
银牌会员
     SuperCleaner
积分 2362
发帖 1133
注册 2008-2-2
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
1113 3331 只得到2B 2211 1122能得到4B 我真的不懂
=====================================
再错就不干了,脚踏实地的路线:
@echo off
setlocal enabledelayedexpansion
set numa=1122
set numb=2211
set /a sameA=0,sameB=0
for /l %%a in (0,1,3) do (
echo !numa:~%%a,1! - !numb:~%%a,1!
if "!numa:~%%a,1!"=="!numb:~%%a,1!" (
set /a sameA+=1,cut=%%a+1
for %%n in (!cut!) do (
set numa=!numa:~0,%%a!x!numa:~%%n!
set numb=!numb:~0,%%a!x!numb:~%%n!
)
)
)
set /a num_n=4-sameA-1,x=0
set numa=%numa:x=%
set numb=%numb:x=%
:lp
for /l %%a in (0,1,%num_n%) do (
if "!numa:~%x%,1!"=="!numb:~%%a,1!" (
set /a sameB+=1
set tmpstr=!numb:~%%a!
set numb=!numb:~0,%%a!x!tmpstr:~1!
goto :break
)
)
:break
if %x% lss %num_n% (set /a x+=1 &goto :lp)
echo %sameA%A%sameB%B
pause
Last edited by 523066680 on 2010-11-14 at 14:31 ]
1113 3331 only gets 2B 2211 1122 can get 4B I really don't understand
=====================================
If I make another mistake, I won't do it anymore, the down-to-earth route:
@echo off
setlocal enabledelayedexpansion
set numa=1122
set numb=2211
set /a sameA=0,sameB=0
for /l %%a in (0,1,3) do (
echo !numa:~%%a,1! - !numb:~%%a,1!
if "!numa:~%%a,1!"=="!numb:~%%a,1!" (
set /a sameA+=1,cut=%%a+1
for %%n in (!cut!) do (
set numa=!numa:~0,%%a!x!numa:~%%n!
set numb=!numb:~0,%%a!x!numb:~%%n!
)
)
)
set /a num_n=4-sameA-1,x=0
set numa=%numa:x=%
set numb=%numb:x=%
:lp
for /l %%a in (0,1,%num_n%) do (
if "!numa:~%x%,1!"=="!numb:~%%a,1!" (
set /a sameB+=1
set tmpstr=!numb:~%%a!
set numb=!numb:~0,%%a!x!tmpstr:~1!
goto :break
)
)
:break
if %x% lss %num_n% (set /a x+=1 &goto :lp)
echo %sameA%A%sameB%B
pause
Last edited by 523066680 on 2010-11-14 at 14:31 ]
|

综合型编程论坛
我的作品索引 |
|
2010-11-14 12:08 |
|
|
jarry0932
初级用户
 
积分 128
发帖 122
注册 2009-9-21
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
貌似小的时候有一个叫猜数字的游戏就是这样的吧。。。
It seems that the number guessing game I played when I was young was like this...
|
|
2010-11-30 21:56 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
首先,定义变量组:
for %%a in (%Han1%) do set/a Ye1+=1&set #!Ye1!=%%a
for %%a in (%Han2%) do set/a Ye2+=1&set @!Ye2!=%%a
A值的获取,根据要求,只要同步依次比较两组识字的第几个就可以了。
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1
因为相同的后的数字就不再用了,所以我先定义个变量,将每组数的各个数字按序号合成:set "Gu1=!Gu1! !Ye2! ",没有比较前,两组数的序号应该是相同的,例如: 1 2 3 4 5 6 7...
每次出现相同时,同时也删除这个序号:set Gu1=!Gu1:%%a =! 因为是对应列的比较,所以两组数的剩余序号一直保持同步相同。
B值的获取,则是嵌套for后组合比较两组数字。对应列上不应有相同,因为在上一步已经删除了他们的序号,所以这里的for循环的是两组的序号。出现相同后删除这个寻列号:if "!#%%a!"=="!@%%b!" set Gu1=!Gu1:%%b =!&set/a Xing2+=Gu2
由于这个Gu1的变化是在第二个for内,所以无法立刻和 for %%b in (!Gu1!) do 的Gu1同步,解决这个问题有两种方法:
1,使用goto跳出这个for,所以把外层的for去掉,使用goto循环
2,不跳出for,但需要使出现相同后,以后的记数空运行,这里使用了set/a Xing2+=Gu2,Gu2=0 。因为Xing2+=Gu2在前,Gu2=0在后,第一次时是加1,以后依然让他继续循环,但每次加的都是0。
要求:两组数字对数一样,每个数字的位数任意,且中间用空格分隔。
方法1: @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&set "Gu1=!Gu1! !Ye2! "
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set Gu1=!Gu1:%%a =!
set Gu2=%Gu1%&call:Gu %Gu1%
echo %Xing1%A%Xing2%B&pause&exit
:Gu
for %%a in (%Gu2%) do if "!#%1!"=="!@%%a!" set/a Xing2+=1&set Gu2=!Gu2:%%a =!&goto:Ye
:Ye
shift
if not "%1"=="" goto:Gu
Last edited by Hanyeguxing on 2010-12-2 at 00:39 ]
First, define the variable groups:
for %%a in (%Han1%) do set/a Ye1+=1&set #!Ye1!=%%a
for %%a in (%Han2%) do set/a Ye2+=1&set @!Ye2!=%%a
The acquisition of value A: According to the requirement, just compare the nth one of the two groups of characters in sequence.
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1
Because the numbers that are the same are no longer used, so I first define a variable to combine each number of each group into a sequence: set "Gu1=!Gu1! !Ye2! ". Before comparison, the sequence numbers of the two groups of numbers should be the same, for example: 1 2 3 4 5 6 7...
Each time a match occurs, this sequence number is also deleted at the same time: set Gu1=!Gu1:%%a =!. Because it is a comparison of corresponding columns, the remaining sequence numbers of the two groups of numbers always remain synchronously the same.
The acquisition of value B: Then, after nested for, combine and compare the two groups of numbers. There should be no matches in the corresponding columns. Because the sequence numbers have been deleted in the previous step, so here the for loop is for the sequence numbers of the two groups. When a match occurs, delete this sequence number: if "!#%%a!"=="!@%%b!" set Gu1=!Gu1:%%b =!&set/a Xing2+=Gu2
Because the change of this Gu1 is inside the second for, so it cannot be synchronized with Gu1 in for %%b in (!Gu1!) do immediately. There are two methods to solve this problem:
1. Use goto to jump out of this for, so remove the outer for and use goto loop
2. Do not jump out of the for, but need to make the counting run empty after a match occurs. Here, set/a Xing2+=Gu2,Gu2=0 is used. Because Xing2+=Gu2 is first, Gu2=0 is later. The first time, it is added by 1, and later it still continues to loop, but each time it adds 0.
Requirement: The number of pairs of the two groups of numbers is the same, each number has any number of digits, and is separated by spaces.
Method 1:
@echo off&setlocal enabledelayedexpansion
for %%a in (1 2) do set Xing%%a=0&set/p Han%%a=Enter the characters of line %%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&set "Gu1=!Gu1! !Ye2! "
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set Gu1=!Gu1:%%a =!
set Gu2=%Gu1%&call:Gu %Gu1%
echo %Xing1%A%Xing2%B&pause&exit
:Gu
for %%a in (%Gu2%) do if "!#%1!"=="!@%%a!" set/a Xing2+=1&set Gu2=!Gu2:%%a =!&goto:Ye
:Ye
shift
if not "%1"=="" goto:Gu
Last edited by Hanyeguxing on 2010-12-2 at 00:39 ]
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-11-30 23:38 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
方法2: @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&set "Gu1=!Gu1! !Ye2! "
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set Gu1=!Gu1:%%a =!
for %%a in (%Gu1%) do (
set Gu2=1
for %%b in (!Gu1!) do if "!#%%a!"=="!@%%b!" set Gu1=!Gu1:%%b =!&set/a Xing2+=Gu2,Gu2=0
)
echo %Xing1%A%Xing2%B&pause&exit
Last edited by Hanyeguxing on 2010-12-2 at 00:40 ]
Method 2:
```batch
@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&set "Gu1=!Gu1! !Ye2! "
for /l %%a in (1,1,%Ye1%) do if "!#%%a!"=="!@%%a!" set/a Xing1+=1&set Gu1=!Gu1:%%a =!
for %%a in (%Gu1%) do (
set Gu2=1
for %%b in (!Gu1!) do if "!#%%a!"=="!@%%b!" set Gu1=!Gu1:%%b =!&set/a Xing2+=Gu2,Gu2=0
)
echo %Xing1%A%Xing2%B&pause&exit
```
Last edited by Hanyeguxing on 2010-12-2 at 00:40 ]
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-12-1 10:14 |
|
|