主题:[活动]急急急急
神鬼天王
[专家分:30] 发布于 2009-09-14 18:58:00
QB求24点(加括号)
快快!
回复列表 (共1个回复)
沙发
phile [专家分:2310] 发布于 2009-09-14 18:59:00
CLS
DIM A(4), B(10), C$(4), D(4)
FOR I = 1 TO 4
INPUT A(I)
NEXT I
FOR I = 1 TO 3
FOR J = I + 1 TO 4
IF A(I) > A(J) THEN SWAP A(I), A(J)
NEXT J, I
FOR I = 1 TO 4
D(I) = A(I)
NEXT I
C$(0) = "+"
C$(1) = "-"
C$(2) = "*"
C$(3) = "/"
DO WHILE B(1) = 0
S = 0
FOR J = 1 TO 24
S = 0
FOR I = 1 TO 4
SELECT CASE B(I)
CASE 0
IF A(I) <> 0 THEN S = S + A(I) ELSE GOTO AA
CASE 1
IF A(I) <> 0 THEN S = S - A(I) ELSE GOTO AA
CASE 2
IF A(I) <> 0 THEN S = S * A(I) ELSE GOTO AA
CASE 3
IF A(I) <> 0 THEN S = S / A(I) ELSE GOTO AA
END SELECT
NEXT I
IF S = 24 THEN
IF B(2) < 2 OR B(2) > 1 AND B(3) < 2 AND B(4) > 1 THEN PRINT "(";
PRINT A(1);
F = 0
FOR M = 2 TO 4
PRINT C$(B(M)); A(M);
IF B(M) < 2 AND B(M + 1) > 1 THEN PRINT ")"; : F = 1
NEXT M
PRINT "="; S
IF F = 0 AND B(2) < 2 THEN PRINT ")";
END IF
S = 0
L = 4
DO WHILE A(L) <= A(L - 1)
L = L - 1
IF L = 0 THEN EXIT FOR
LOOP
T = 4
DO WHILE A(T) <= A(L - 1)
T = T - 1
LOOP
SWAP A(T), A(L - 1)
FOR H = L TO 3
FOR P = H + 1 TO 4
IF A(H) > A(P) THEN SWAP A(H), A(P)
NEXT P, H
A(0) = 0
NEXT J
AA: K = 4
DO WHILE B(K) = 3
B(K) = 0
K = K - 1
LOOP
B(K) = B(K) + 1
FOR I = 1 TO 4
A(I) = D(I)
NEXT I
LOOP
我来回复