|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
水仙花数
建议使用3重循环……
Narc narcissistic number
It is suggested to use three nested loops...
|
|
2008-4-11 21:10 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 17 楼』:
球落地问题(程序20):
使用 LLM 解释/回答一下
因cmd局限于10位数字,用这种方法仅能精确算出球第10次落地弹起的高度,对于10次经过的距离不能精确计算(郁闷中):
@echo off
set /a n=100*10000000&set m=0
:begin
if %m% gtr 0 set str=%str%+2*%n%
if %m% gtr 0 set /a str=%str%/10000000
set /a n/=2&set /a m+=1
if %m% lss 10 goto begin
set /a str=%str%+100/2
echo 第10次球落地后共经过%str%米的距离
:lp
if "%n:~,-6%"=="" set n=0%n%
if "%n:~,-6%"=="" goto lp
echo 第10次弹起为0.%n%米
pause>nul
Last edited by zw19750516 on 2008-4-11 at 10:05 PM ]
Because cmd is limited to 10-digit numbers, using this method can only accurately calculate the height of the ball bouncing up on the 10th landing, and the distance traveled in 10 passes cannot be accurately calculated (depressed):
@echo off
set /a n=100*10000000&set m=0
:begin
if %m% gtr 0 set str=%str%+2*%n%
if %m% gtr 0 set /a str=%str%/10000000
set /a n/=2&set /a m+=1
if %m% lss 10 goto begin
set /a str=%str%+100/2
echo The total distance after the 10th landing of the ball is %str% meters
:lp
if "%n:~,-6%"=="" set n=0%n%
if "%n:~,-6%"=="" goto lp
echo The 10th bounce is 0.%n% meters
pause>nul
Last edited by zw19750516 on 2008-4-11 at 10:05 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-4-11 21:42 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 18 楼』:
年纪问题(程序28):
使用 LLM 解释/回答一下
@echo off&setlocal enabledelayedexpansion
set n=10
for %%i in (2,2,2,2) do set /a n+=%%i&cls&echo 第五个人年纪是!n!岁
pause>nul
```@echo off&setlocal enabledelayedexpansion
set n=10
for %%i in (2,2,2,2) do set /a n+=%%i&cls&echo The fifth person is!n! years old
pause>nul
```
|

批处理之家新域名:www.bathome.net |
|
2008-4-11 22:26 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
水仙花算法 确实三重循环为好 下面的忘记是那位版主写的 记得是namejm 版主写的:
@echo off
echo.
echo 三位的水仙花数有:
echo.
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do (
for /l %%j in (0,1,9) do (
for /l %%k in (0,1,9) do (
set a=%%i
set b=%%j
set c=%%k
set num1=!a!!b!!c!
set /a num2=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !num1! equ !num2! echo !num1!
)
)
)
pause
goto :eof
The Narcissistic number algorithm is indeed better with three nested loops. The following one was forgotten who the moderator wrote, but I remember it was written by moderator namejm:
@echo off
echo.
echo Three-digit narcissistic numbers are:
echo.
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do (
for /l %%j in (0,1,9) do (
for /l %%k in (0,1,9) do (
set a=%%i
set b=%%j
set c=%%k
set num1=!a!!b!!c!
set /a num2=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !num1! equ !num2! echo !num1!
)
)
)
pause
goto :eof
|

简单!简单!再简单! |
|
2008-4-11 22:34 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 20 楼』:
奇数个数(程序83):
使用 LLM 解释/回答一下
@echo off
set /a str=6*7*7*7*7*7*4
echo 能组成%str%个奇数
pause>nul
@echo off
set /a str=6*7*7*7*7*7*4
echo There can be %str% odd numbers formed
pause>nul
|

批处理之家新域名:www.bathome.net |
|
2008-4-11 22:35 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2008-4-11 22:34:
水仙花算法 确实三重循环为好 下面的忘记是那位版主写的 记得是namejm 版主写的:
@echo off
echo.
echo 三位的水仙花数有:
echo.
setlocal ...
我不这样认为,我的代码就能很好地实现了(开始是少打了个*),何必还要写这么复杂的代码。
Originally posted by terse at 2008-4-11 22:34:
The narcissistic number algorithm is indeed better with three nested loops. The following one I forgot who the moderator wrote, I remember it was written by moderator namejm:
@echo off
echo.
echo Three-digit narcissistic numbers are:
echo.
setlocal ...
I don't think so. My code can implement it very well (I initially missed a *), why write such complicated code.
|

批处理之家新域名:www.bathome.net |
|
2008-4-11 22:41 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
从效率讲,3重循环比从111循环到999好。
对程序代码来说效率是第一的。
In terms of efficiency, a 3-layer loop is better than looping from 111 to 999.
For program code, efficiency is the top priority.
|
|
2008-4-11 23:47 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
如果代简单的话 那就直接SET/a var
var=!str:~,1!!str:~,1!*!str:~,1!+!str:~1,1!*!str:~1,1!*!str:~1,1!.....
If it's simple, then directly SET/a var
var=!str:~,1!!str:~,1!*!str:~,1!+!str:~1,1!*!str:~1,1!*!str:~1,1!.....
|

简单!简单!再简单! |
|
2008-4-11 23:54 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
个人认为 15楼和19楼没什么效率上的区别。
倒是15楼把延迟变量放到for内部有点多此一举。
若想证明效率谁的高,最好靠事实说话
求 1-10000 的水仙花数,同时记录下批处理运行时间,不就有结果了?
Personally, there is no difference in efficiency between floor 15 and floor 19.
However, it is unnecessary for floor 15 to put the delay variable inside the for.
If you want to prove which one has higher efficiency, it is best to rely on facts.
To find the narcissistic numbers from 1 to 10000 and record the batch processing running time, isn't that a result?
|

致精致简! |
|
2008-4-12 00:16 |
|
|
plp626
银牌会员
     钻石会员
积分 2278
发帖 1020
注册 2007-11-19
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数
15楼的:@echo off
setlocal enabledelayedexpansion
for /l %%i in (100,1,999) do (
set str=%%i
set/a a=!str:~,1!, b=!str:~1,1!, c=!str:~2,1!
set /a var=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !var! equ !str! echo !str!
)
pause
19楼的:@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do for /l %%j in (0,1,9) do for /l %%k in (0,1,9) do (
set/a a=%%i,b=%%j,c=%%k
set num1=!a!!b!!c!
set /a num2=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !num1! equ !num2! echo !num1!
)
pause
Last edited by plp626 on 2008-4-12 at 12:51 AM ]
The so-called "narcissistic number" refers to a three-digit number whose sum of the cubes of its digits is equal to the number itself.
15th floor:@echo off
setlocal enabledelayedexpansion
for /l %%i in (100,1,999) do (
set str=%%i
set/a a=!str:~,1!, b=!str:~1,1!, c=!str:~2,1!
set /a var=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !var! equ !str! echo !str!
)
pause
19th floor:@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do for /l %%j in (0,1,9) do for /l %%k in (0,1,9) do (
set/a a=%%i,b=%%j,c=%%k
set num1=!a!!b!!c!
set /a num2=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !num1! equ !num2! echo !num1!
)
pause
Last edited by plp626 on 2008-4-12 at 12:51 AM ]
|

山外有山,人外有人;低调做人,努力做事。
进入网盘(各种工具)~~ 空间~~cmd学习 |
|
2008-4-12 00:43 |
|
|
sh19871122
新手上路

积分 18
发帖 8
注册 2008-4-4
状态 离线
|
|
2008-4-12 07:12 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
循环次数上一样麽?
哪个更少呢?
取每位,和将几位合起来那个更快呢?
Are the number of loops the same?
Which one is less?
Which is faster, taking each digit or combining several digits?
|
|
2008-4-12 14:45 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
Originally posted by slore at 2008-4-12 14:45:
循环次数上一样麽?
哪个更少呢?
取每位,和将几位合起来那个更快呢?
求 1-10000 的水仙花数,同时记录下批处理运行时间,不就有结果了?
Originally posted by slore at 2008-4-12 14:45:
Are the number of loops the same?
Which one is less?
Which is faster, taking each digit or combining several digits?
To find the Armstrong numbers from 1 to 10000 and record the batch processing time, wouldn't that give the result?
|

致精致简! |
|
2008-4-12 15:00 |
|
|
plp626
银牌会员
     钻石会员
积分 2278
发帖 1020
注册 2007-11-19
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2008-4-12 03:00 PM:
求 1-10000 的水仙花数,同时记录下批处理运行时间,不就有结果了?
两个时间一样,误差在0.01秒以内,小于%time%的“系统”误差。
Originally posted by 26933062 at 2008-4-12 03:00 PM:
Find the narcissistic numbers from 1 to 10000, and record the batch processing running time, then you will get the result?
The two times are the same, with an error within 0.01 seconds, which is less than the "system" error of %time%.
|

山外有山,人外有人;低调做人,努力做事。
进入网盘(各种工具)~~ 空间~~cmd学习 |
|
2008-4-12 16:09 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
如果你可以测试到99999999999999999999999999999999999的话……
If you can test up to 99999999999999999999999999999999999...
|
|
2008-4-12 16:31 |
|