![]() |
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-11-11 18:03 |
47,815 topics / 349,930 posts / today 0 new / 48,291 members |
| DOS批处理 & 脚本技术(批处理室) » Set out a question, all picked from C language questions by me |
| Printable Version 3,600 / 38 |
| Floor16 slore | Posted 2008-04-11 21:10 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Narc narcissistic number
It is suggested to use three nested loops... |
|
| Floor17 bat-zw | Posted 2008-04-11 21:42 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
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):
[ Last edited by zw19750516 on 2008-4-11 at 10:05 PM ] |
|
| Floor18 bat-zw | Posted 2008-04-11 22:26 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
```@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 ``` |
|
| Floor19 terse | Posted 2008-04-11 22:34 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
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:
|
|
| Floor20 bat-zw | Posted 2008-04-11 22:35 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
| Floor21 bat-zw | Posted 2008-04-11 22:41 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
Originally posted by terse at 2008-4-11 22:34: |
|
| Floor22 slore | Posted 2008-04-11 23:47 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
In terms of efficiency, a 3-layer loop is better than looping from 111 to 999.
For program code, efficiency is the top priority. |
|
| Floor23 terse | Posted 2008-04-11 23:54 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
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!..... |
|
| Floor24 26933062 | Posted 2008-04-12 00:16 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
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? |
|
| Floor25 plp626 | Posted 2008-04-12 00:43 |
| 银牌会员 Posts 1,020 Credits 2,278 | |
|
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 19th floor: @echo off [ Last edited by plp626 on 2008-4-12 at 12:51 AM ] |
|
| Floor26 sh19871122 | Posted 2008-04-12 07:12 |
| 新手上路 Posts 8 Credits 18 | |
| Floor27 slore | Posted 2008-04-12 14:45 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Are the number of loops the same?
Which one is less? Which is faster, taking each digit or combining several digits? |
|
| Floor28 26933062 | Posted 2008-04-12 15:00 |
| 银牌会员 Posts 879 Credits 2,268 | |
Originally posted by slore at 2008-4-12 14:45: To find the Armstrong numbers from 1 to 10000 and record the batch processing time, wouldn't that give the result? |
|
| Floor29 plp626 | Posted 2008-04-12 16:09 |
| 银牌会员 Posts 1,020 Credits 2,278 | |
Originally posted by 26933062 at 2008-4-12 03:00 PM: The two times are the same, with an error within 0.01 seconds, which is less than the "system" error of %time%. |
|
| Floor30 slore | Posted 2008-04-12 16:31 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
If you can test up to 99999999999999999999999999999999999...
|
|
| Prev 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |