用VBS写出给5个人分10个苹果的方法?

来源:百度知道 编辑:UC知道 时间:2024/05/16 07:42:20
条件:
5个人:A,B,C,D,E
10个苹果

例出所有方法,如
A 1,B 1,C 1,D 1,E 6
A 1,B 1,C 1,D 2,E 5
A 1,B 1,C 1,D 3,E 4
...

这就是组合问题。C10,5

set fso=createobject("scripting.filesystemobject")
set ws=createobject("wscript.shell")
set file=fso.createtextfile("OUT.txt",2)
for a=1 to 6
for b=1 to 6
for c=1 to 6
for d=1 to 6
for e=1 to 6
if a+b+c+d+e=7 then
h=h+1
s=s & "│" & a & vbtab & "│" & b & vbtab & "│" & c & vbtab & "│" & d & vbtab & "│" & e &vbtab &"│" &vbcrlf & "├———┼———┼———┼———┼———┤"&vbcrlf

end if
next
next
next
next
next
s=Left(s,Len(s)-Len("├———┼———┼———┼———┼———┤"&vbcrlf))
file.write "给5个人分10个苹果一共有" & h &"种方法" & vbcrlf & vbcrlf
file.write "┌———┬———┬———┬———┬———┐"& VBcrlf
file.write "│A" & vbtab &"│B" & vbtab &"│C" & vbtab &"│D" & vbtab &"│E" & vbtab &"│" & VBcrlf
file.write "┝━━