主题:[活动]螺旋阵
神鬼天王
[专家分:30] 发布于 2009-09-28 19:14:00
如n=15
7 6 5
8 1 4 15
9 2 3 14
10 11 12 13
回复列表 (共2个回复)
沙发
phile [专家分:2310] 发布于 2009-09-28 19:15:00
CLS
INPUT N
N1 = INT(SQR(N))
IF INT(SQR(N)) <> SQR(N) THEN N1 = N1 + 1
DIM A(N1, N1)
K = N1 * N1 + 1
IF N1 MOD 2 = 0 THEN
FOR I = 1 TO N1 \ 2 + 1
FOR J = I TO N1 + 1 - I
K = K - 1
IF K <= N THEN A(J, N1 + 1 - I) = K
NEXT J
FOR J = N1 - I TO I STEP -1
K = K - 1
IF K <= N THEN A(N1 + 1 - I, J) = K
NEXT J
FOR J = N1 - I TO I STEP -1
K = K - 1
IF K <= N THEN A(J, I) = K
NEXT J
FOR J = I + 1 TO N1 - I
K = K - 1
IF K <= N THEN A(I, J) = K
NEXT J
NEXT I
ELSE
FOR I = 1 TO (N1 + 1) \ 2
FOR J = N1 + 1 - I TO I STEP -1
K = K - 1
IF K <= N THEN A(J, I) = K
NEXT J
FOR J = I + 1 TO N1 + 1 - I
K = K - 1
IF K <= N THEN A(I, J) = K
NEXT J
FOR J = I + 1 TO N1 + 1 - I
K = K - 1
IF K <= N THEN A(J, N1 + 1 - I) = K
NEXT J
FOR J = N1 - I TO I + 1 STEP -1
K = K - 1
IF K <= N THEN A(N1 + 1 - I, J) = K
NEXT J
NEXT I
END IF
FOR I = 1 TO N1
FOR J = 1 TO N1
IF A(I, J) <> 0 THEN PRINT USING "####"; A(I, J); ELSE PRINT " ";
NEXT J
PRINT
NEXT I
板凳
phile [专家分:2310] 发布于 2009-09-28 19:16:00
内往外
我来回复