主题:急急急急急!!!!!!!!!!!!!!
oqoq
[专家分:130] 发布于 2009-05-10 15:45:00
求助:成比例的三位数:将1—9共9个数字分成三组,分别组成三个三位数,且使这三个三位数构成1:2:3的比例,试求出所有满足条件的三个三位数。(用穷举法)[em10]
回复列表 (共5个回复)
沙发
oqoq [专家分:130] 发布于 2009-05-16 12:56:00
我回帖那么热情没人照顾我的帖
板凳
天天和和 [专家分:1420] 发布于 2009-06-11 22:38:00
用一个循环变量表示第1个数
再用这个变量乘以2等于第2个数
再用这个变量乘以2等于第3个数
然后将这三个数连接起来,比较,有没有重复的
3 楼
1054122 [专家分:750] 发布于 2009-06-22 17:02:00
CLS
FOR a = 1 TO 9
FOR b = 0 TO 9
FOR c = 0 TO 9
FOR d = 1 TO 9
FOR e = 0 TO 9
FOR f = 0 TO 9
FOR g = 1 TO 9
FOR h = 0 TO 9
FOR i = 0 TO 9
IF (a = b) + (b = c) + (c = d) + (d = e) + (e = f) + (f = g) + (g = h) + (h = i) = 0 THEN
x = a * 100 + b * 10 + c
y = d * 100 + e * 10 + f
z = g * 100 + h * 10 + i
IF y / x = 2 AND z / x = 3 THEN
PRINT x; y; z
END IF
END IF
NEXT i, h, g, f, e, d, c, b, a
END
比较暴力,我再想想
4 楼
1054122 [专家分:750] 发布于 2009-06-22 17:09:00
CLS
FOR x = 100 TO 999
FOR y = 100 TO 999
FOR z = 100 TO 999
x1 = x MOD 10: x2 = x \ 10 MOD 10: x3 = x \ 100
y1 = y MOD 10: y2 = y \ 10 MOD 10: y3 = y \ 100
z1 = z MOD 10: z2 = z \ 10 MOD 10: z3 = z \ 100
c = 0
IF (x1 = c) + (x2 = c) + (x3 = c) + (y1 = c) + (y2 = c) + (y3 = c) + (z1 = c) + (z2 = c) + (z3 = c) = 0 THEN
IF (x1 = x2) + (x2 = x3) + (z1 = x3) + (z2 = z1) + (z2 = z3) + (y3 = z3) + (z3 = z2) + (z2 = z1) = 0 THEN
IF z / x = 3 AND y / x = 2 THEN
PRINT x; y; z
END IF
END IF
END IF
NEXT z
NEXT y
NEXT x
END
5 楼
oqoq [专家分:130] 发布于 2009-06-23 17:22:00
怎么评分
我来回复