|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『楼 主』:
[已解决]罗列用不同数字组成的所有三位数
使用 LLM 解释/回答一下
想写一个三位数的数字组合(如001,002...999),排除有两位数相等的(如001,112,313,449 等)组合以及三位数都相等的(如000,111...999)。
注:012,021,120,102,210,201这里只取任意一种,其它以此类推。
Last edited by jmz573515 on 2007-1-26 at 06:41 PM ]
I want to write a combination of three-digit numbers (such as 001, 002...999), excluding combinations where two digits are equal (such as 001, 112, 313, 449, etc.) and combinations where all three digits are equal (such as 000, 111...999).
Note: For 012, 021, 120, 102, 210, 201, only one of them is taken, and the rest are similar.
Last edited by jmz573515 on 2007-1-26 at 06:41 PM ]
|
|
2007-1-27 02:00 |
|
|
zhclvip
初级用户
 
积分 138
发帖 50
注册 2007-1-23
状态 离线
|
 『第 2 楼』:
合你心愿
使用 LLM 解释/回答一下
dim msg
combine "0123456789",3,""
msgbox msg
Sub Combine(sar,num,str)
If num=0 Then
msg=msg&str&";"
Else
For i=1 To Len(sar)
Call Combine(Right(sar,Len(sar)-i),num-1,str&Mid(sar,i,1))
Next
End If
End Sub
```vb
dim msg
combine "0123456789",3,""
msgbox msg
Sub Combine(sar,num,str)
If num=0 Then
msg=msg&str&";"
Else
For i=1 To Len(sar)
Call Combine(Right(sar,Len(sar)-i),num-1,str&Mid(sar,i,1))
Next
End If
End Sub
```
|
|
2007-1-27 02:10 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
好,学习了。
(现在受限不能加分,过后补上。)
Okay, learned it.
(Currently restricted from adding points, will make up later.)
|
|
2007-1-27 02:13 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
 『第 4 楼』:
使用 LLM 解释/回答一下
我跟一个BAT版的,是用组合数的思路:
@echo off
set str=0123456789
cd.>result.txt
setlocal enabledelayedexpansion
for /l %%i in (0,1,7) do (
set /a num1=%%i+1
for /l %%j in (!num1!,1,8) do (
set /a num2=%%j+1
for /l %%k in (!num2!,1,9) do (
set /a count+=1
echo !str:~%%i,1!!str:~%%j,1!!str:~%%k,1!>>result.txt
)
)
)
echo 各个数位上的数字互不相同,且组成该数的数字与其他数中的数字不完全相同的三位数有 %count% 个>>result.txt
start result.txt
遵照ccwan的建议,加上了统计结果。
Last edited by namejm on 2007-1-26 at 11:08 PM ]
I am using the idea of combinations with a BAT version:
@echo off
set str=0123456789
cd.>result.txt
setlocal enabledelayedexpansion
for /l %%i in (0,1,7) do (
set /a num1=%%i+1
for /l %%j in (!num1!,1,8) do (
set /a num2=%%j+1
for /l %%k in (!num2!,1,9) do (
set /a count+=1
echo !str:~%%i,1!!str:~%%j,1!!str:~%%k,1!>>result.txt
)
)
)
echo The three-digit numbers where the digits at each position are all different and the digits forming the number are not completely the same as those in other numbers have %count% in total>>result.txt
start result.txt
Following ccwan's suggestion, the statistical result is added.
Last edited by namejm on 2007-1-26 at 11:08 PM ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-27 02:40 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
斑斑的代码总是那么精彩,欣赏~~
Banban's code is always so wonderful, appreciate it~~
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-1-27 03:01 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
|
2007-1-27 03:01 |
|
|
tongwandou
初级用户
 
积分 112
发帖 50
注册 2007-4-15
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
二楼用C写得,比较简单!我喜欢4楼给出的代码,谢谢二位!
The second floor is written in C, relatively simple! I like the code given by the fourth floor, thank you two!
|
|
2007-4-19 10:02 |
|
|
minmin888
初级用户
 
积分 127
发帖 62
注册 2007-4-19
状态 离线
|
|
2007-5-8 10:37 |
|
|