超简单的一道题,有步骤翻倍

来源:百度知道 编辑:UC知道 时间:2024/05/28 11:18:56
A:2.9元, B:4.7元, C:7.2元, D:10.6元, E:14.9元。用60元买十件,有几种方法?

第1种方式:A3件;B1件;C5件;D1件;E0件。计算公式为:2.9*3+4.7*1+7.2*5+10.6*1+14.9*0=60
第2种方式:A4件;B1件;C4件;D0件;E1件。计算公式为:2.9*4+4.7*1+7.2*4+10.6*0+14.9*1=60
第3种方式:A4件;B2件;C1件;D3件;E0件。计算公式为:2.9*4+4.7*2+7.2*1+10.6*3+14.9*0=60
第4种方式:A5件;B2件;C0件;D2件;E1件。计算公式为:2.9*5+4.7*2+7.2*0+10.6*2+14.9*1=60

用vbscript代码如下:
Dim a,b,c,d,e,n,nSum,nCount
n = 1
for a =0 to 20
for b =0 to 12
for c =0 to 8
for d =0 to 6
for e =0 to 4

nSum = 2.9*a + 4.7*b + 7.2*c + 10.6*d + 14.9*e
nCount = a+b+c+d+e
if nCount = 10 and ccur(nSum) = 60 then
Response.Write "第"+cstr(n)+"种方式:"+"A"+ cstr(a)+"件;B"+ cstr(b)+"件;C"+ cstr(c)+"件;D"+ cstr(d)+"件;E" + cstr(e)+"件。计算公式为:2.9*"+cstr(a)+"+4.7*"+cstr(b)+"+7.2*"+cstr(c)+"+10.6*"+cstr(d)+"+14.9*"+cstr(e)+"="+cstr(nSum)+" <br>"