主题: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个回复)
21 楼
Lovely哆啦 [专家分:1360] 发布于 2007-03-30 16:55:00
CLS
INPUT N
DIM A(N, N)
FOR I = 1 TO 4: READ X1(I), Y1(I), X2(I), Y2(I): NEXT I
DATA 1,0,1,-1,0,1,1,1,-1,0,-1,1,0,-1,0,0
X = 0: Y = 1
FOR I = N - 1 TO 0 STEP -2
IF I = 0 THEN A(X + 1, Y) = N * N: GOTO 10
FOR J = 1 TO 4
FOR K = 1 TO I
X = X + X1(J): Y = Y + Y1(J): S = S + 1: A(X, Y) = S
NEXT K
X = X + X2(J): Y = Y + Y2(J)
NEXT J
NEXT I
10 FOR I = 1 TO N
FOR J = 1 TO N
PRINT USING "###"; A(I, J);
NEXT J: PRINT
NEXT I
END
22 楼
黑白猪-- [专家分:420] 发布于 2007-04-01 16:57:00
自学
[em1]
23 楼
盗版单均昊 [专家分:0] 发布于 2007-04-02 11:10:00
CLS
INPUT N
DIM A(N, N)
FOR I = 1 TO 4: READ X1(I), Y1(I), X2(I), Y2(I): NEXT I
DATA 1,0,1,-1,0,1,1,1,-1,0,-1,1,0,-1,0,0
Y = 1
FOR I = N - 1 TO 0 STEP -2
IF I = 0 THEN A(X + 1, Y) = N * N: GOTO 10
FOR J = 1 TO 4
FOR K = 1 TO I
X = X + X1(J): Y = Y + Y1(J)
S = S + 1
A(X, Y) = S
NEXT K
X = X + X2(J): Y = Y + Y2(J)
NEXT J
NEXT I
10 FOR I = 1 TO N
FOR J = 1 TO N
PRINT USING "####"; A(I, J);
NEXT J: PRINT
NEXT I
END
24 楼
Matodied [专家分:7560] 发布于 2007-04-17 21:37:00
我只用了20分钟……
CLS
INPUT n
DIM a(n, n): x = 1: y = 1: s = 0
k = n
DO
DO WHILE a(x, y) = 0
s = s + 1
a(x, y) = s
x = x + 1
IF x > k THEN EXIT DO
LOOP
x = x - 1: y = y + 1
DO WHILE a(x, y) = 0
s = s + 1
a(x, y) = s
y = y + 1
IF y > k THEN EXIT DO
LOOP
y = y - 1: x = x - 1
DO WHILE a(x, y) = 0
s = s + 1
a(x, y) = s
x = x - 1
IF x < 1 THEN EXIT DO
LOOP
x = x + 1: y = y - 1
DO WHILE a(x, y) = 0
s = s + 1
a(x, y) = s
y = y - 1
IF y < 1 THEN EXIT DO
LOOP
x = x + 1: y = y + 1: k = k - 1
LOOP UNTIL s = n * n
FOR i = 1 TO n: FOR j = 1 TO n
PRINT USING "####"; a(i, j);
NEXT j: PRINT : NEXT i: END
25 楼
mickeyice [专家分:200] 发布于 2007-04-18 16:15:00
..没什么挑战
数组
1 2 6 7 14
3 5 8 13 15
4 9 12 16 19
10 11 17 18 20
这个比较烦琐点
26 楼
黑白猪-- [专家分:420] 发布于 2007-05-07 16:28:00
用路径吧
27 楼
黑白猪-- [专家分:420] 发布于 2007-05-07 16:29:00
用路径
28 楼
ninke [专家分:60] 发布于 2007-05-10 11:12:00
倒,思路10分钟不到就出来了,但是写程序用了半个多小时。
cls
dim m(4,4)
n=0:s=3:a=1
for i=1 to 4
n=n+1
m(i,1)=n
next i
x=4:y=1
1 for j=1 to s
y=y+a
n=n+1
m(x,y)=n
next j
a=-a
2 for i=1 to s
x=x+a
n=n+1
m(x,y)=n
next i
s=s-1
if s=0 then goto 3
goto 1
3 for i=1 to 4
for j=1 to 4
print m(i,j);
next j
print
next i
end
29 楼
ninke [专家分:60] 发布于 2007-05-10 16:58:00
[quote]..没什么挑战
数组
1 2 6 7 14
3 5 8 13 15
4 9 12 16 19
10 11 17 18 20
这个比较烦琐点[/quote]
其实你这个数组比楼主的要简单多了,你恐怕搞错了吧。哈哈。
30 楼
美味的汽水 [专家分:70] 发布于 2007-05-10 21:30:00
cls
input n
dim a(n,n)
for x= 1 to (n+1)\2
i=x
for a= x to n+1-x
s=s+1:a(i,a)=s
next
j=n+1-x
for b=x+1 to n+1-x
s=s+1:a(b,j)=s
next
i=n+1-x
for c=n-x to x step -1
s=s+1:a(i,c)=s
next
j=x
for d=n-x to 1+x step -1
s=s+1:a(d,j)=s
next d
next
for i=1 to n
for j=1 to n
print a(i,j);
next
print
next
三分钟解决
我来回复