D im A(99, 99) As String Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, n t = 1 Max = 2 * n - 1 For i = 1 To Max For j = 1 To Max A(i, j) = " " If j <= n + t - 1 And j >= n Then A(i, j) = t - (j - n) If j >= n - t + 1 And j <= n Then A(i, j) = t - (n - j) Print #2, A(i, j); Next j If i < n Then t = t + 1 Else t = t - 1 End If Print #2, Next i Close #2 Close #1 End Sub
高仔你的方法 我看不懂ˊˋ 我的印出來是正方形=ˋ=" VB 表單顯示 和 TXT檔顯示 的資料排序不一樣 不知道要參考哪一個@@" Private Sub Form_Load() Dim n As Integer Open App.Path & "\in.txt" For Input As #1 Input #1, n Close #1 Open App.Path & "\out.txt" For Output As #2 For i = 1 To n For q = 1 To (n - i) * 2 Print #2, " "; Next q For j = 1 To i Print #2, Str(j); Next j For j = i - 1 To 1 Step -1 Print #2, Str(j); Next j Print #2, Next i For i = n - 1 To 1 Step -1 For q = 1 To (n - i) * 2 Print #2, " "; Next q For j = 1 To i Print #2, Str(j); Next j For j = i - 1 To 1 Step -1 Print #2, Str(j); Next j Print #2, Next i Close #2 End Sub
第二個部分是高仔說的對齊部分。 可以在print #2,a(i,j);前,將每個要印出去的a(i,j)都變成固定長度再印出去,比如說長度3,(或是用輸入的數字的長度加1), 例如: if a(i,j) <10 then s = " " & a(i,j) '雙引號裡用兩個空白 else s = " " & a(i,j) '雙引號裡用1個空白 end if
Dim a(50, 50) As Integer, Li(100) As String Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, qqq For i = 1 To qqq For j = 1 To qqq a(i, j + i - 1) = j Next j Next i q = 1 For i = 1 To qqq For j = qqq To 2 Step -1 If a(j, i) = 0 Then Li(q) = Li(q) & " " Else Li(q) = Li(q) & Str(a(j, i)) End If Next j q = q + 1 Next i For i = 1 To qqq For j = 1 To qqq If a(j, i) = 0 Then Li(i) = Li(i) & " " Else Li(i) = Li(i) & Str(a(j, i)) End If Next j Next i For i = 1 To qqq Print #2, Li(i) Next i For i = qqq - 1 To 1 Step -1 Print #2, Li(i) Next i Close #2 Close #1 End Sub
Open App.Path & "\in.txt" For Input As #1 Input #1, n Close
Open App.Path & "\out.txt" For Output As #2 For i = 1 To n ans = ans & i pans = ans Do While Len(pans) < n pans = " " & pans Loop If i >= 2 Then tmp = i - 1 & tmp Print #2, pans & tmp Next i
For i = 1 To n - 1 pans = " " & Mid(pans, 1, n - 1) tmp = Mid(tmp, 2, n - 2) Print #2, pans & tmp Next i Close #2
Dim ans(100) As String Public Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Dim k As String k = "" Me.Hide Input #1, x For i = 1 To x k = Trim(k) k = String(x - i, " ") & k & i nk = k & StrReverse(Left(k, Len(k) - 1))
Print #2, nk ans(i) = nk Next i
For i = (x - 1) To 1 Step -1 Print #2, ans(i) Next i Close #2 Close #1 End End Sub
D im A(99, 99) As String
回覆刪除Private Sub Form_Load()
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, n
t = 1
Max = 2 * n - 1
For i = 1 To Max
For j = 1 To Max
A(i, j) = " "
If j <= n + t - 1 And j >= n Then A(i, j) = t - (j - n)
If j >= n - t + 1 And j <= n Then A(i, j) = t - (n - j)
Print #2, A(i, j);
Next j
If i < n Then
t = t + 1
Else
t = t - 1
End If
Print #2,
Next i
Close #2
Close #1
End Sub
正巧這兩天的題型皆是數字排序類型
回覆刪除如今天這題,若N>10也就是超過1位數
菱形數字方塊會變形的頗嚴重的
原因是前面之數字為1位數,而後面之數字為2位數
若要排序整齊,則會如同昨日"九九乘法"一般冗長
不知老師是否有比較建議使用的方法呢?
高仔你的方法 我看不懂ˊˋ
回覆刪除我的印出來是正方形=ˋ="
VB 表單顯示 和 TXT檔顯示 的資料排序不一樣 不知道要參考哪一個@@"
Private Sub Form_Load()
Dim n As Integer
Open App.Path & "\in.txt" For Input As #1
Input #1, n
Close #1
Open App.Path & "\out.txt" For Output As #2
For i = 1 To n
For q = 1 To (n - i) * 2
Print #2, " ";
Next q
For j = 1 To i
Print #2, Str(j);
Next j
For j = i - 1 To 1 Step -1
Print #2, Str(j);
Next j
Print #2,
Next i
For i = n - 1 To 1 Step -1
For q = 1 To (n - i) * 2
Print #2, " ";
Next q
For j = 1 To i
Print #2, Str(j);
Next j
For j = i - 1 To 1 Step -1
Print #2, Str(j);
Next j
Print #2,
Next i
Close #2
End Sub
高仔,Y揚好,
回覆刪除這個題目,一看也是轉得很暈。
分兩個部分來看,
一是像高仔那樣做出所要的數字,這部分的雙迴圈就已經很煩了。
第二個部分是高仔說的對齊部分。
可以在print #2,a(i,j);前,將每個要印出去的a(i,j)都變成固定長度再印出去,比如說長度3,(或是用輸入的數字的長度加1),
例如:
if a(i,j) <10 then
s = " " & a(i,j) '雙引號裡用兩個空白
else
s = " " & a(i,j) '雙引號裡用1個空白
end if
Y揚好,
回覆刪除你的程式和我的想法一樣啊,應該會對的吧,怎麼你說是印出來的是正方形呢?
等於將這題的圖形切成四分來做,上面兩半,又合成一個雙迴圈來做。沒錯啊,難道是「對齊」問題嗎?
老師
回覆刪除這題阿,我不太知道要怎麼做,
我是先研究出來中間的十字架了
我有想過要繼續用十字架的方式
把數字的部分往上和往下增加
如
1
2
12321
2
1
然後我是想把他分兩部分
做成
1
121
12321
12321
121
1
然後用if,如果說已經有寫入數字的話
就不要在繼續寫入了
可是
想了很久,卻還是想不出來要怎麼做...
Dim a(50, 50) As Integer, Li(100) As String
回覆刪除Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, qqq
For i = 1 To qqq
For j = 1 To qqq
a(i, j + i - 1) = j
Next j
Next i
q = 1
For i = 1 To qqq
For j = qqq To 2 Step -1
If a(j, i) = 0 Then
Li(q) = Li(q) & " "
Else
Li(q) = Li(q) & Str(a(j, i))
End If
Next j
q = q + 1
Next i
For i = 1 To qqq
For j = 1 To qqq
If a(j, i) = 0 Then
Li(i) = Li(i) & " "
Else
Li(i) = Li(i) & Str(a(j, i))
End If
Next j
Next i
For i = 1 To qqq
Print #2, Li(i)
Next i
For i = qqq - 1 To 1 Step -1
Print #2, Li(i)
Next i
Close #2
Close #1
End Sub
Private Sub Form_Activate()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Input #1, n
Close
Open App.Path & "\out.txt" For Output As #2
For i = 1 To n
ans = ans & i
pans = ans
Do While Len(pans) < n
pans = " " & pans
Loop
If i >= 2 Then tmp = i - 1 & tmp
Print #2, pans & tmp
Next i
For i = 1 To n - 1
pans = " " & Mid(pans, 1, n - 1)
tmp = Mid(tmp, 2, n - 2)
Print #2, pans & tmp
Next i
Close #2
End Sub
因為社課時就很想做這題了,所以還是做完了 =D
Dim ans(100) As String
回覆刪除Public Sub Form_Load()
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Dim k As String
k = ""
Me.Hide
Input #1, x
For i = 1 To x
k = Trim(k)
k = String(x - i, " ") & k & i
nk = k & StrReverse(Left(k, Len(k) - 1))
Print #2, nk
ans(i) = nk
Next i
For i = (x - 1) To 1 Step -1
Print #2, ans(i)
Next i
Close #2
Close #1
End
End Sub
19分