主题: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个回复)
沙发
啊远 [专家分:2610] 发布于 2006-10-04 15:11:00
晕!我居然用了一个晚上!
板凳
老大徒伤悲 [专家分:29120] 发布于 2006-10-04 20:37:00
http://www.programfan.com/club/showbbs.asp?id=194916
这个程序写了(连做饭、吃饭、洗碗)用了三个小时。
不知道有什么讲究没有?
3 楼
maxumi [专家分:2200] 发布于 2006-10-05 07:19:00
10min左右
4 楼
mingzhentanq [专家分:60] 发布于 2006-10-05 16:20:00
把你们的程序给我看看啊!
看看那个的好!最主要的是精简!
注意:用QBASIC写!
5 楼
啊远 [专家分:2610] 发布于 2006-10-05 17:55:00
OPTION BASE 1
DIM Img(9, 9) AS INTEGER ' Images array
DIM Row AS INTEGER ' rows
DIM Col AS INTEGER ' cols
DIM Jsq AS INTEGER ' temp
DIM CS AS INTEGER ' temp
DIM X1 AS INTEGER ' left layer
DIM X2 AS INTEGER ' right layer
DIM Y1 AS INTEGER ' top layer
DIM Y2 AS INTEGER ' bottom layer
DIM tempStr AS STRING ' temp
DIM Index AS INTEGER ' temp
DIM SS AS INTEGER
Row = 9
Col = 9
X1 = 1
Y1 = 1
X2 = Col
Y2 = Row
IF Row < Col THEN
SS = INT(Row / 2) + (Row MOD 2)
ELSE
SS = INT(Col / 2) + (Col MOD 2)
END IF
DO WHILE CS <= SS
CS = CS + 1
' ==================
' left
' ==================
IF X1 <= X2 THEN
FOR Index = Y1 TO Y2
Jsq = Jsq + 1
Img(Index, X1) = Jsq
NEXT
X1 = X1 + 1
END IF
' ==================
' bottom
' ==================
IF Y1 <= Y2 THEN
FOR Index = X1 TO X2
Jsq = Jsq + 1
Img(Y2, Index) = Jsq
NEXT
Y2 = Y2 - 1
END IF
' ==================
' right
' ==================
IF X2 >= X1 THEN
FOR Index = Y2 TO Y1 STEP -1
Jsq = Jsq + 1
Img(Index, X2) = Jsq
NEXT
X2 = X2 - 1
END IF
' ==================
' top
' ==================
IF Y2 >= Y1 THEN
FOR Index = X2 TO X1 STEP -1
Jsq = Jsq + 1
Img(Y1, Index) = Jsq
NEXT
Y1 = Y1 + 1
END IF
LOOP
DIM ICOL AS INTEGER
DIM IROW AS INTEGER
tempStr = ""
FOR IROW = 1 TO Row STEP 1
FOR ICOL = 1 TO Col STEP 1
tempStr = tempStr + STR$(Img(IROW, ICOL)) + STRING$(LEN(STR$(CINT(Col * Row))) - LEN(STR$(Img(IROW, ICOL))), CHR$(32))
NEXT
tempStr = tempStr + CHR$(13) + CHR$(10)
NEXT
PRINT tempStr
==========================
晕我再贴一下! VB改qb只改 CStr 为 STR$ Chr 为 Chr$ & 改为 +
呵呵! 我这个应该算简洁易懂的吧!
6 楼
啊远 [专家分:2610] 发布于 2006-10-05 17:55:00
1 32 31 30 29 28 27 26 25
2 33 56 55 54 53 52 51 24
3 34 57 72 71 70 69 50 23
4 35 58 73 80 79 68 49 22
5 36 59 74 81 78 67 48 21
6 37 60 75 76 77 66 47 20
7 38 61 62 63 64 65 46 19
8 39 40 41 42 43 44 45 18
9 10 11 12 13 14 15 16 17
7 楼
老大徒伤悲 [专家分:29120] 发布于 2006-10-05 19:13:00
那我也谈谈用qb界面的思路,但就不做了,因为我没有安装这个。
首先使用input输入高和宽
然后用高和宽定义一个二维数组n(gao,kuan)
设定
HangShu = 0
LieShu = 0
FangXiang = 1 '1-下,2-右,3-上,4-左
QuanShu = 0
四个变量的初值
For i = 1 To Gao * Kuan '每个数字
'计算行数、列数
Select Case FangXiang
Case 1
If HangShu = Gao - QuanShu - 1 Then
FangXiang = 2
End If
HangShu = HangShu + 1
Case 2
If LieShu = Kuan - QuanShu - 2 Then
FangXiang = 3
End If
LieShu = LieShu + 1
Case 3
If HangShu = QuanShu + 2 Then
FangXiang = 4
End If
HangShu = HangShu - 1
Case 4
If LieShu = QuanShu + 2 Then
FangXiang = 1
QuanShu = QuanShu + 1
End If
LieShu = LieShu - 1
End Select
n(hangshu,lieshu)=i
Next i
for i=1 to gao
for j=1 to kuan
?tab(5*j); n(i,j);
next j
?
next i
end
我不能检验,有写错关键字的地方,包含阿
8 楼
hs3180 [专家分:530] 发布于 2006-10-06 12:07:00
为什么不用一个2维数组存,用一个常量方向数组控制方向呢?
大概2MIN就能写完了
9 楼
mingzhentanq [专家分:60] 发布于 2006-10-06 13:53:00
8 楼的,你详细一下你的丝路!
10 楼
diylym [专家分:30] 发布于 2006-10-06 15:55:00
' ================== 这是干什么用的?是输出吗?[em15][em13]
我来回复