中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-29 18:11
47,813 topics / 349,918 posts / today 0 new / 48,278 members
DOS批处理 & 脚本技术(批处理室) » [Challenge 2] Detection and Calculation of Variables [Difficulty: ★]
Printable Version  5,084 / 38
Floor16 flyinspace Posted 2007-05-01 05:35
银牌会员 Posts 517 Credits 1,206
Originally posted by bjsh at 2007-4-30 04:16 PM:
Spared some time to write this..
The result is: 24691356902469134

Not bad, but temporary files will be generated.

In fact, there is a way to not generate temporary files. youxia01 gave us the best hint:)
Floor17 bjsh Posted 2007-05-01 05:44
银牌会员 Posts 621 Credits 2,000
Originally, I didn't want to generate temporary files either;

Originally, I wanted to replace / with alt+13;

But I didn't achieve my idea; I really wanted to go and debug to see;

But I was short on time.;

So I just wrote it down..
Floor18 zhoushijay Posted 2007-05-01 05:50
高级用户 Posts 375 Credits 845
set "num1=qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
set "num2=aaaaa2/23456789012345678/asdfssasd/asdaa"

These two numbers should be
2341234567890123456
+ 223456789012345678
-----------------------------------------
2564691356902469134
It seems that there are numbers mixed among the letters in the front.

[ Last edited by zhoushijay on 2007-4-30 at 04:52 PM ]
Floor19 flyinspace Posted 2007-05-01 06:07
银牌会员 Posts 517 Credits 1,206
Originally posted by zhoushijay at 2007-4-30 04:50 PM:
set "num1=qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
set "num2=aaaaa2/23456789012345678/asdfssasd/asdaa"

These two numbers should be
2341234567890123456
+ 22345678901234567 ...


Oh. We just need the group of pure numbers.
Floor20 lxmxn Posted 2007-05-01 06:20
版主 Posts 4,938 Credits 11,386
Originally posted by bjsh at 2007-4-30 16:44:
Originally didn't want to generate temporary files;

Originally wanted to replace / with alt+13;

But my idea wasn't realized; really wanted to go debug and take a look;

But unfortunately time was relatively tight.;

Just wrote it down..

To replace / with a newline, you can refer to this:
Floor21 everest79 Posted 2007-05-01 06:28
金牌会员 Posts 1,127 Credits 2,564
The original content contains some non-standard or hard-to-understand parts. Here is the translation:

I originally wrote a big number addition, and it was modified according to the requirements

Floor22 flyinspace Posted 2007-05-01 06:38
银牌会员 Posts 517 Credits 1,206
SET/A1/T2&&SET/AT1=T1+1
SET/AT2=1/(T1/10)||SET T2=0
This is a bit unclear?

SET/A1/T2 && SET/AT1=T1+1

Brother event79, can you explain it?
Floor23 everest79 Posted 2007-05-01 06:47
金牌会员 Posts 1,127 Credits 2,564
This is to perform the addition of single digits incrementally from right to left by character positions.

SET/A 1/T2 && SET/AT1=T1+1 // set /a 1/t2 is used to judge whether t2 (t2 is the carry of the previous cycle) is zero. If not, add 1 to the current result t1.

SET/AT2=1/(T1/10) || SET T2=0 // set /a t2=1/(t1/10) is used to judge whether the current cycle result (t1) is greater than 10. If it is greater than ten, t2 will be assigned 1 (the previous step of the next cycle). If it is less than ten, set the carry t2 to zero.
Floor24 flyinspace Posted 2007-05-01 06:56
银牌会员 Posts 517 Credits 1,206
Originally posted by everest79 at 2007-4-30 05:47 PM:
This is adding the units digits incrementally from right to left by character position

SET/A1/T2&&SET/AT1=T1+1 // set /a 1/t2 is used to judge whether t2 (t2 is the carry from the previous loop) is zero. If not, add 1 to the current result t1
SET/AT2=1/(T1/10)||SET T2=0 // set /a t2=1/(t1/10) is used to judge whether the current loop result (t1) is greater than 10. If it is greater than ten, t2 will be assigned 1 (for the next loop step). If it is less than ten, the carry t2 is set to zero



Thanks brother for the explanation, I understand the meaning of this sentence!

New question: Why set/a1/t2&&set/at1=t1+1
What's the use of adding this /?

According to your statement: This sentence is equivalent to>
set /a xxx= 1 / t2
Using the particularity of set /a: 
If xxx is less than 1, then xxx= 0
Being 0 satisfies the condition. Then t2 += 1

Learned another trick. It's a bit similar to the feeling of set /p? And without the = sign.
Floor25 everest79 Posted 2007-05-01 07:00
金牌会员 Posts 1,127 Credits 2,564
set /a a=1+1 can be abbreviated as set/aa=1+1. At that time, I just saw it in someone else's example, so I wrote it like that. It's not a good writing habit
Floor26 flyinspace Posted 2007-05-01 07:06
银牌会员 Posts 517 Credits 1,206
Originally posted by everest79 at 2007-4-30 06:00 PM:
set /a a=1+1 can be abbreviated as set/aa=1+1. At that time, I just saw it in someone else's example, so I wrote it like that. It's not a good writing habit.


set /a a=1/a is also equivalent to set /a1/a??
Floor27 everest79 Posted 2007-05-01 07:59
金牌会员 Posts 1,127 Credits 2,564
No, it's not.
`set /a a=1/a` is a calculation assignment.
`set /a 1/a` is just a calculation.
Floor28 youxi01 Posted 2007-05-02 17:35
高级用户 Posts 247 Credits 846 From 湖南==》广东
There seems to be a bit of an issue with the code for 21F. Let's continue to make modifications.

The testing is as follows:


I also send a section of immature code (when there are more segments, the efficiency is relatively high):
Floor29 flyinspace Posted 2007-05-02 19:02
银牌会员 Posts 517 Credits 1,206
Originally posted by youxi01 at 2007-5-2 04:35 AM:
There seems to be a bit of an issue with the code for 21F; it needs to be modified further:
Test as follows:


I'll also post a piece of immature code myself (if there are many segments...

The code is really tiring to read..

Is there an algorithm??

Give a hint?
Floor30 youxi01 Posted 2007-05-03 15:17
高级用户 Posts 247 Credits 846 From 湖南==》广东
::code by youxi01@cn-dos.net
@echo off & setlocal enabledelayedexpansion

set "str1=qwer/asdf2/asd34f/13546641/asdf/aaaa"
set "str2=aaaaa2/45321/asdfssasd/asdaa"

call :GetNum "%str1%" num1
call :GetNum "%str2%" num2

call :Split %num1%

REM Mnum saves the number of segments of the result (used to accept the maximum number of segments);
REM Reset the value of num to 0 to continue calling the "function"
REM flag is the carry flag, if it is 1, the next segment number is added by 1; here it is the initial value, set to 1.
set/a Mnum=%num%,num=0,flag=0

call :Split %num2%
if %Mnum% LSS %num% set/a Mnum=%num%
set/a Mnum_=%Mnum%-1

for /l %%i in (1 1 %Mnum_%) do (
set/a Rnum%%i+=!flag!
if !Rnum%%i! GTR 10000 set/a flag=1

REM Adding 000 in front is to fill the number, to prevent numbers with less than 4 digits like 333.
set Rnum%%i=000!Rnum%%i!

set Rnum%%i=!Rnum%%i:~-4!
set Rstr=!Rnum%%i!!Rstr!)

set/a Rnum%Mnum%+=%flag%
echo !Rnum%Mnum%!!Rstr!

pause>nul

:GetNum OBJ Res
for /f "delims=/ tokens=1,*" %%i in ("%~1") do (

REM Use whether it is less than a to detect whether it is a number. If it is, it must be less than a (no matter how many digits it is)
REM If a number is detected, exit.
if %%i LSS a set %2=%%i & goto :eof

REM Loop detection;
call :GetNum "%%j" %2
) & goto :eof

:Split OBJ
set str=%~1
set/a num+=1

REM If the cut number is less than 10000, set its own value to the original value plus the number and exit;
if %str% LSS 10000 set/a Rnum%num%+=%str% & goto :eof

REM Use the willsort method to eliminate errors caused by set/a calculation similar to 0001;
set/a Rnum%num%+=10000%str:~-4%%%10000

set str=%str:~0,-4%
call :Split "%str%"
Prev  1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023