|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『楼 主』:
[挑战2] 变量的检测和计算[难度:★]
使用 LLM 解释/回答一下
set "num1=qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
set "num2=aaaaa2/23456789012345678/asdfssasd/asdaa"
目标:在上面两个条件中提取出纯数字的组合,并计算这两个数字的和,然后正确输出到屏幕上。(提取上面两个字符串只可以使用一个子程序,因为是测试的关系,只给出2个字符串的组合)
编写条件:cmd (help里包含的命令)
难点:随机的数字存在位和计算时的溢出
目标人群:有一定批处理基础的人。
注:挑战会逐渐提高难度。(大家尽量就自己会做的做出来)
编写积分奖励:3分。
完成提取任务的一分,完成计算任务的二分。。
加分不是目的。是对能力的一种肯定。
2楼正确获取了 随机的字符串,但在处理计算时问题上有点问题。
输出为科学记数法。。但要求是:输出精确数值。。(完成第一项,加一分)
Last edited by flyinspace on 2007-4-30 at 01:19 PM ]
set "num1=qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
set "num2=aaaaa2/23456789012345678/asdfssasd/asdaa"
Goal: Extract the combinations of pure numbers from the above two conditions, calculate the sum of these two numbers, and then output the result correctly to the screen. (Only one subroutine can be used to extract the above two strings, because it is for testing, only two string combinations are given)
Writing conditions: cmd (commands included in help)
Difficulty: Overflow in digit position and calculation of random numbers
Target audience: People with certain batch processing foundation.
The challenge will gradually increase in difficulty. (Everyone try to do what you can)
Writing points reward: 3 points.
One point for completing the extraction task, two points for completing the calculation task.
Adding points is not the purpose. It is an affirmation of ability.
The second floor correctly obtained the random string, but there was a problem in the processing calculation.
The output is in scientific notation. But the requirement is: output the exact value. (Complete the first item, add one point)
Last edited by flyinspace on 2007-4-30 at 01:19 PM ]
|

知,不觉多。不知,乃求知 |
|
2007-4-30 13:51 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
由于对P一窍不通 写个VBS吧
num1="qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
num2="aaaaa2/23456789012345678/asdfssasd/asdaa"
numarr=split(num1&"/"&num2,"/")
For i=0 To UBound(numarr)
if IsNumeric(numarr(i)) then
num=num+CDbl(numarr(i))
end if
Next
msgbox num
msgbox FormatNumber(num,0,,,0)
Last edited by baomaboy on 2007-4-30 at 04:37 PM ]
Since I know nothing about P, write a VBS.
num1="qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
num2="aaaaa2/23456789012345678/asdfssasd/asdaa"
numarr=split(num1&"/"&num2,"/")
For i=0 To UBound(numarr)
if IsNumeric(numarr(i)) then
num=num+CDbl(numarr(i))
end if
Next
msgbox num
msgbox FormatNumber(num,0,,,0)
Last edited by baomaboy on 2007-4-30 at 04:37 PM ]
|

好多菩提树,好多明镜台。本来好多物,好多的尘埃。 |
|
2007-4-30 14:48 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Originally posted by baomaboy at 2007-4-30 01:48 AM:
由于对P一窍不通 写个VBS吧
num1="qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
num2="aaaaa2/23456789012345678/asdfssasd/asdaa"
numarr=split(num1&"/"&num2,"/")
For i=0 To UBound(numarr)
if IsNumeric(numarr(i)) then
num=num+CDbl(numarr(i))
end if
Next
msgbox num
挑战失败:
原因见附件:
我们要求正确输出 结果。
Last edited by flyinspace on 2007-4-30 at 02:35 AM ]
Originally posted by baomaboy at 2007-4-30 01:48 AM:
Since I know nothing about P, write a VBS:
num1="qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
num2="aaaaa2/23456789012345678/asdfssasd/asdaa"
numarr=split(num1&"/"&num2,"/")
For i=0 To UBound(numarr)
if IsNumeric(numarr(i)) then
num=num+CDbl(numarr(i))
end if
Next
msgbox num
Challenge failed:
Reasons see attachment:
We require the correct output result.
Last edited by flyinspace on 2007-4-30 at 02:35 AM ]
附件
1: 1.JPG (2007-4-30 15:31, 3.91 KiB, 下载附件所需积分 1 点
,下载次数: 2)
|

知,不觉多。不知,乃求知 |
|
2007-4-30 15:18 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
楼上的,二楼结果是正确的,E+16是科学计数的写法代表N*(1后面有16个零)
24691356902469134=2.46913569024691*10000000000000000=2.46913569024691E+16
The person upstairs, the result of the second floor is correct. E+16 is the scientific notation representing N*(1 followed by 16 zeros).
24691356902469134 = 2.46913569024691*10000000000000000 = 2.46913569024691E+16
|
|
2007-4-30 15:41 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
不好意思,我也知道他的结果正确。。。。
但我们的要求是 :
输出:24691356902469134
这个结果,而不是2.46913569024691E+16 这个结果。。
这个算我没有说清楚。。。。
若我们的数字再变化一下呢?? 有 30位呢?
我们要求的是精确。。。呵呵。。
最后谢谢 zh159的指出。
I'm sorry, I also know his result is correct...
But our requirement is:
Output: 24691356902469134
This result, not the result of 2.46913569024691E+16...
This is my unclear explanation...
What if our number changes a bit?? There are 30 digits??
We require precision... Hehe.
Finally, thank zh159 for pointing out.
|

知,不觉多。不知,乃求知 |
|
2007-4-30 15:46 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by flyinspace at 2007-4-30 15:46:
不好意思,我也知道他的结果正确。。。。
但我们的要求是 :
输出:24691356902469134
这个结果,而不是2.46913569024691E+16 这个结果。。
这个 ...
那就格式化一下吧:
msgbox FormatNumber(num,0,,,0)
不过估计你那最后两位34没人能得到吧,早几年在Excel中就发现超过15位后全显示0,也许是微软觉得15位已经够用了限制了吧,呵呵,开玩笑的,反正我是用不到15位不深究了,有人知道指点下。
Last edited by baomaboy on 2007-4-30 at 04:51 PM ]
Originally posted by flyinspace at 2007-4-30 15:46:
I'm sorry, I also know that his result is correct...
But our requirement is:
Output: 24691356902469134
This result, not the result of 2.46913569024691E+16...
This...
Then format it:
msgbox FormatNumber(num,0,,,0)
But I estimate that no one can get the last two digits 34. A few years ago, I found in Excel that all display 0 after exceeding 15 digits. Maybe Microsoft thinks that 15 digits are enough and limits it, heh heh, just kidding. Anyway, I don't need 15 digits and won't delve into it. If someone knows, please give a pointer.
Last edited by baomaboy on 2007-4-30 at 04:51 PM ]
|

好多菩提树,好多明镜台。本来好多物,好多的尘埃。 |
|
2007-4-30 16:35 |
|
|
digger
初级用户
  游荡的孤魂
积分 79
发帖 29
注册 2007-4-2 来自 湖南
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
计算两数的和这个话题论坛里曾经有过专题讨论,在精华帖里,有难度啊。
There was a special discussion on the topic of calculating the sum of two numbers in the forum, and it's difficult in the essence posts.
|
|
2007-4-30 20:15 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
我曾经写过 大数字的 计算(乘法)的,计算数字在 100 位以内。
还有,看2F的代码 似乎 两个字符串 只是其中有一项目 是数字哦!(就是说 没有其它的特殊情况罗,比如:有两项数字又该怎么处理等?)
Last edited by youxi01 on 2007-4-30 at 08:56 PM ]
I once wrote calculations (multiplication) of large numbers, with numbers within 100 digits.
Also, looking at the code of 2F, it seems that only one of the two strings is a number! (That is to say, there are no other special cases, such as what to do if there are two numbers, etc.?)
Last edited by youxi01 on 2007-4-30 at 08:56 PM ]
|
|
2007-4-30 20:55 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
提供一下思路:(因为马上要工作,就不能给出详细代码了。同时,因为搬家的原因,短期内要上不了网,所以也可能暂离联盟。)
1、关于各字符段的提取,昨天的挑战一就有相关代码。
2、提取出的各字符段,是否是数字相关判断的问题。此问题解决办法有三:
1>利用set/a 的特殊性,此办法不严谨,无法防止字符段恰好为0的情况。
2>利用findstr+正则,比较精确,但效率不高。
3>个人比较推荐的办法:拿字母(包括汉字)直接和数字比较大小,如果,某字符段是纯数字,它就一定比 a 小。缺点:无法处理特殊字符。
3、有关特大数字的计算。我们可以采取分段计算的办法,已经有相关讨论,我曾经也写过相关代码,在此不作赘述。
Provide ideas: (Because I'm going to work soon, I can't give detailed code. Also, because of moving, I won't be able to access the Internet in the short term, so I may leave the union temporarily.)
1. Regarding the extraction of each character segment, there is related code in Challenge 1 yesterday.
2. The problem of whether the extracted each character segment is related to digital judgment. There are three solutions to this problem:
1> Use the particularity of set/a, this method is not strict, and cannot prevent the situation where the character segment is exactly 0.
2> Use findstr + regular expression, which is relatively precise, but inefficient.
3> The method that I personally recommend: directly compare letters (including Chinese characters) with numbers. If a certain character segment is purely digital, it must be smaller than a. Disadvantage: Cannot handle special characters.
3. Regarding the calculation of extremely large numbers. We can adopt the method of segmental calculation. There has been related discussion, and I have also written related code, which will not be repeated here.
|
|
2007-4-30 21:26 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 10 楼』:
给出 计算 大数字的演示,提取好象大家都会?
使用 LLM 解释/回答一下
@echo off & setlocal EnableDelayedExpansion
set "a=123456789012485642424543456"
set "b=234567890000000000000005678"
call :GetLen "%a%"
set "Len1=%Len%"
call :GetLen "%b%"
set "Len2=%Len%"
set "s="
set "bit=0"
set "count=0"
:recompute
set /a "count+=1"
if %Len1% GEQ 9 (
set "str1=%a:~-9%
set "a=%a:~0,-9%"
set /a "Len1-=9"
) else (
set "str1=%a%"
set "a=0"
)
if %Len2% GEQ 9 (
set "str2=%b:~-9%"
set "b=%b:~0,-9%
set /a "Len2-=9"
) else (
set "str2=%b%"
set "b=0"
)
call :formatstr %str1%
set "str1=%xxx%
call :formatstr %str2%
set "str2=%xxx%
set /a "num=!str1!+!str2!+!bit!"
call :GetLen "%num%"
if '%Len% GTR 9' (
set "bit=%num:~0,1%"
set "num=%num:~-9%"
)
set "s=%num%%s%"
echo : %str1%+%str2%=%s%
if "%a%"=="0" (
if "%b%" == "0" (
goto :END
)
)
goto :recompute
:formatstr _str_
set "xxx=%~1"
:reformat
set "lll=9"
if "%xxx:~0,1%"=="0" (
set "xxx=!xxx:~1,%lll%!
set /a "lll-=1"
goto :reformat
)
goto :EOF
:GetLen
set "string=%~1"
for /l %%i in (0,1,255) do (
if "!string:~%%i,1!"=="" (
set "Len=%%i"
goto :EOF
)
)
goto :EOF
:END
echo ——————————————————————————
echo 最后答案为:%s%
echo ——————————————————————————
echo 程序演示结束,任意键退出 & pause>nul
Last edited by flyinspace on 2007-4-30 at 04:29 PM ]
@echo off & setlocal EnableDelayedExpansion
set "a=123456789012485642424543456"
set "b=234567890000000000000005678"
call :GetLen "%a%"
set "Len1=%Len%"
call :GetLen "%b%"
set "Len2=%Len%"
set "s="
set "bit=0"
set "count=0"
:recompute
set /a "count+=1"
if %Len1% GEQ 9 (
set "str1=%a:~-9%
set "a=%a:~0,-9%"
set /a "Len1-=9"
) else (
set "str1=%a%"
set "a=0"
)
if %Len2% GEQ 9 (
set "str2=%b:~-9%"
set "b=%b:~0,-9%
set /a "Len2-=9"
) else (
set "str2=%b%"
set "b=0"
)
call :formatstr %str1%
set "str1=%xxx%
call :formatstr %str2%
set "str2=%xxx%
set /a "num=!str1!+!str2!+!bit!"
call :GetLen "%num%"
if '%Len% GTR 9' (
set "bit=%num:~0,1%"
set "num=%num:~-9%"
)
set "s=%num%%s%"
echo : %str1%+%str2%=%s%
if "%a%"=="0" (
if "%b%" == "0" (
goto :END
)
)
goto :recompute
:formatstr _str_
set "xxx=%~1"
:reformat
set "lll=9"
if "%xxx:~0,1%"=="0" (
set "xxx=!xxx:~1,%lll%!
set /a "lll-=1"
goto :reformat
)
goto :EOF
:GetLen
set "string=%~1"
for /l %%i in (0,1,255) do (
if "!string:~%%i,1!"=="" (
set "Len=%%i"
goto :EOF
)
)
goto :EOF
:END
echo ——————————————————————————
echo Final answer: %s%
echo ——————————————————————————
echo Program demonstration ends, press any key to exit & pause>nul
Last edited by flyinspace on 2007-4-30 at 04:29 PM ]
|

知,不觉多。不知,乃求知 |
|
2007-4-30 22:23 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
num1="qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
num2="aaaaa2/23456789012345678/asdfssasd/asdaa"
len1=len(num1)
len2=len(num2)
for i=1 to len1
nu1=mid (num1,i,1)
on error resume next
a=int(nu1)
if err.number=0 then
b=b&a
end if
next
for a=1 to len2
nu2=mid (num2,a,1)
on error resume next
d=int(nu2)
if err.number=0 then
s=s&d
end if
next
s=int(s)
b=int(b)
he=s+b
msgbox(he)正确的答案应该是2564691356902469134,我用计算器算了2遍
Last edited by zhoushijay on 2007-4-30 at 04:53 PM ]
num1="qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
num2="aaaaa2/23456789012345678/asdfssasd/asdaa"
len1=len(num1)
len2=len(num2)
for i=1 to len1
nu1=mid (num1,i,1)
on error resume next
a=int(nu1)
if err.number=0 then
b=b&a
end if
next
for a=1 to len2
nu2=mid (num2,a,1)
on error resume next
d=int(nu2)
if err.number=0 then
s=s&d
end if
next
s=int(s)
b=int(b)
he=s+b
msgbox(he) The correct answer should be 2564691356902469134, I calculated it twice with a calculator
Last edited by zhoushijay on 2007-4-30 at 04:53 PM ]
|
|
2007-5-1 00:58 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by youxi01 at 2007-4-30 20:55:
我曾经写过 大数字的 计算(乘法)的,计算数字在 100 位以内。
还有,看2F的代码 似乎 两个字符串 只是其中有一项目 是数字哦!(就是说 没有其 ...
当数值型字串与数值在一起做运算时,数值型字串被当作数值
When a numeric string and a number are operated together, the numeric string is treated as a number
|

好多菩提树,好多明镜台。本来好多物,好多的尘埃。 |
|
2007-5-1 04:18 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by zhoushijay at 2007-4-30 11:58 AM:
nu1=mid (num1,i,1)
on error resume next
a=int(nu1)
if err.number=0 then
b=b&a
end if
next
for a=1 to len2
nu2=mid (num2,a,1)
on error resume next
d=int(nu2)
if err.number=0 then
s=s&d
end if
next
s=int(s)
b=int(b)
he=s+b
msgbox(he)
正确的答案应该是2564691356902469134,我用计算器算了2遍
=1234567890123456
23456789012345678+
--------------------------------
24691356902469134
怎么比也没有算错啊??
怎么会是
2564691356902469134呢?
Last edited by flyinspace on 2007-4-30 at 04:10 PM ]
Originally posted by zhoushijay at 2007-4-30 11:58 AM:
nu1=mid (num1,i,1)
on error resume next
a=int(nu1)
if err.number=0 then
b=b&a
end if
next
for a=1 to len2
nu2=mid (num2,a,1)
on error resume next
d=int(nu2)
if err.number=0 then
s=s&d
end if
next
s=int(s)
b=int(b)
he=s+b
msgbox(he)
The correct answer should be 2564691356902469134. I calculated it twice with a calculator.
=1234567890123456
23456789012345678+
--------------------------------
24691356902469134
No matter how I compare, I didn't make a mistake.
Why is it
2564691356902469134?
Last edited by flyinspace on 2007-4-30 at 04:10 PM ]
|

知,不觉多。不知,乃求知 |
|
2007-5-1 05:01 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
 『第 14 楼』:
使用 LLM 解释/回答一下
抽出了点时间 写了这个..
结果为:24691356902469134
- @echo off & setlocal enabledelayedexpansion
- set "num1=qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
- set "num2=aaaaa2/23456789012345678/asdfssasd/asdaa"
- set "num1=%num1:/= %" & call :get_number !num1! & set "num1=!t!"
- set "num2=%num2:/= %" & call :get_number !num2! & set "num2=!t!"
- set "result="
- :c_loop
- set /a x=%num1:~-8%
- set /a y=%num2:~-8%
- set /a z=%x%+%y%
- if defined flag set /a z=%z%+%flag%
- set "flag=%z:~0,-8%" >>nul 2>>nul && set "z=%z:~-8%"
- set "num1=%num1:~0,-8%"
- set "num2=%num2:~0,-8%"
- set "result=%z%%result%"
- if not defined num1 if not defined num2 set "result=%flag%%result%" & goto :show
- if not defined num1 set /a num1=0
- if not defined num2 set /a num2=0
- goto c_loop
- :show
- echo %result% & pause & goto :eof
- :get_number
- :loop
- echo %1 >>tmp.txt & shift
- if not "%1"=="" goto :loop
- for /f %%a in ('findstr /r "^" tmp.txt') do set "t=%%a"
- del tmp.txt
BJSH发表于: 2007-04-30 16:04
Spared some time to write this..
Result: 24691356902469134
- @echo off & setlocal enabledelayedexpansion
- set "num1=qwer/asdf2/asd34f/1234567890123456/asdf/aaaa"
- set "num2=aaaaa2/23456789012345678/asdfssasd/asdaa"
- set "num1=%num1:/= %" & call :get_number !num1! & set "num1=!t!"
- set "num2=%num2:/= %" & call :get_number !num2! & set "num2=!t!"
- set "result="
- :c_loop
- set /a x=%num1:~-8%
- set /a y=%num2:~-8%
- set /a z=%x%+%y%
- if defined flag set /a z=%z%+%flag%
- set "flag=%z:~0,-8%" >>nul 2>>nul && set "z=%z:~-8%"
- set "num1=%num1:~0,-8%"
- set "num2=%num2:~0,-8%"
- set "result=%z%%result%"
- if not defined num1 if not defined num2 set "result=%flag%%result%" & goto :show
- if not defined num1 set /a num1=0
- if not defined num2 set /a num2=0
- goto c_loop
- :show
- echo %result% & pause & goto :eof
- :get_number
- :loop
- echo %1 >>tmp.txt & shift
- if not "%1"=="" goto :loop
- for /f %%a in ('findstr /r "^" tmp.txt') do set "t=%%a"
- del tmp.txt
BJSH posted on: 2007-04-30 16:04
|
|
2007-5-1 05:16 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by zhoushijay at 2007-4-30 11:58:
nu1=mid (num1,i,1)
on error resume next
a=int(nu1)
if err.number=0 then
b=b&a
end if
next
for a=1 to len2
nu2=mid (num2,a,1)
on error resume next
d=int(nu2)
if err.number=0 then
s=s&d
end if
next
s=int(s)
b=int(b)
he=s+b
msgbox(he)
正确的答案应该是2564691356902469134,我用计算器算了2遍
16位数+17位数怎么也不可能得出19位数啊?
1234567890123456
+23456789012345678
--------------------------------------
=24691356902469134
=================
2564691356902469134
Originally posted by zhoushijay at 2007-4-30 11:58:
nu1=mid (num1,i,1)
on error resume next
a=int(nu1)
if err.number=0 then
b=b&a
end if
next
for a=1 to len2
nu2=mid (num2,a,1)
on error resume next
d=int(nu2)
if err.number=0 then
s=s&d
end if
next
s=int(s)
b=int(b)
he=s+b
msgbox(he)
The correct answer should be 2564691356902469134, I calculated it twice with a calculator
How can a 16-digit number plus a 17-digit number result in a 19-digit number?
1234567890123456
+23456789012345678
--------------------------------------
=24691356902469134
=================
2564691356902469134
|
|
2007-5-1 05:17 |
|