主题:QB45,MOZ。。螺旋的 ··············
mingzhentanq
[专家分:60] 发布于 2006-10-04 14:45:00
螺旋的 1 12 11 10
2 13 16 9
3 14 15 8
4 5 6 7
看到这题目时开始,你能用多少时间写出代码?
回复列表 (共32个回复)
31 楼
小小DAVID [专家分:300] 发布于 2009-11-12 21:39:00
CLS
INPUT n
DIM a(n + 1, n + 1)
bj = n
i = 1: j = 1
s = 1
DO
DO WHILE a(i, j) = 0 AND (i <= bj)
a(i, j) = s
s = s + 1
i = i + 1
LOOP
i = i - 1
j = j + 1
DO WHILE a(i, j) = 0 AND j <= bj
a(i, j) = s
s = s + 1
j = j + 1
LOOP
j = j - 1
i = i - 1
DO WHILE a(i, j) = 0 AND i >= n + 1 - bj
a(i, j) = s
s = s + 1
i = i - 1
LOOP
i = i + 1
j = j - 1
DO WHILE a(i, j) = 0 AND j >= n + 1 - bj
a(i, j) = s
s = s + 1
j = j - 1
LOOP
i = i + 1
j = j + 1
bj = bj - 1
LOOP UNTIL s > n * n
FOR i = 1 TO n
FOR j = 1 TO n
PRINT USING "####"; a(j, i);
NEXT j
PRINT
NEXT i
END
一定要加分,不然,呵呵
哼哼
32 楼
小小DAVID [专家分:300] 发布于 2009-11-12 21:41:00
CLS
INPUT n
DIM a(n + 1, n + 1)
bj = n
i = 1: j = 1
s = 1
DO
DO WHILE a(i, j) = 0 AND (i <= bj)
a(i, j) = s
s = s + 1
i = i + 1
LOOP
i = i - 1
j = j + 1
DO WHILE a(i, j) = 0 AND j <= bj
a(i, j) = s
s = s + 1
j = j + 1
LOOP
j = j - 1
i = i - 1
DO WHILE a(i, j) = 0 AND i >= n + 1 - bj
a(i, j) = s
s = s + 1
i = i - 1
LOOP
i = i + 1
j = j - 1
DO WHILE a(i, j) = 0 AND j >= n + 1 - bj
a(i, j) = s
s = s + 1
j = j - 1
LOOP
i = i + 1
j = j + 1
bj = bj - 1
LOOP UNTIL s > n * n
FOR i = 1 TO n
FOR j = 1 TO n
PRINT USING "####"; a(j, i);
NEXT j
PRINT
NEXT i
END
我来回复