任给出4个非0的不同数字,求出由这4个数字组成的所有不同的4位数.

来源:百度知道 编辑:UC知道 时间:2024/05/30 15:03:40
要求输出的所有4位数按照从小到大的顺序排列(每行中不要有多余的空格)

高中学生都会的东西~~
找本数看看

4!=24种组合

asp写:

<%
dim numarr,str
function p(tmp,str)
if len(str)=1 then
response.write tmp&str&vbcrlf
else
dim arr
if right(str,1)="," then str=left(str,len(str)-1)
arr=split(str,",")
for i=0 to ubound(arr)
p tmp&arr(i),replace(replace(str,Cstr(arr(i))&",",""),","&Cstr(arr(i)),"")
next
end if
end function
p "","1,2,3,4" '不同的数字组合请修改此处,保证它们的是从小到大排列

%>

输出:
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321

要是对回答的内容有问题,或认为不妥,百度消息我。
(在消息的内容里加上问题的网址哦)