內容 :
已知一(m x n)矩陣A,我們常常需要用到另一個將A中之行與列調換的矩陣。這個動作叫做矩陣的翻轉。舉例來說,若
現在 請您針對所讀取到的矩陣進行翻轉。
A = [ 3 1 2 ] 8 5 4
則
AT = [ 3 8 ] 1 5 2 4
現在 請您針對所讀取到的矩陣進行翻轉。
輸入說明 :
第一行會有兩個數字,分別為 列(row)<100 和 行(column)<100,緊接著就是這個矩陣的內容
輸出說明 :
直接輸出翻轉後的矩陣
範例輸入 :
2 3
3 1 2
8 5 4
範例輸出 :
3 8
1 5
2 4
Private Sub Form_Load()
回覆刪除Me.Hide
Dim a(1000)
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x, n
b = 0
For j = 1 To x
For i = 1 To n
b = b + 1
Input #1, a(b)
Next
Next
For i = 1 To n
ans = a(i) & " " & a(i + n)
Print #2, ans
ans = ""
Next
Close
Close
End
End Sub
小冰好,
回覆刪除程式錯誤。
如果輸入的x,n是3,4呢?或是更大呢?
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Dim a()
Input #1, x, n
ReDim a(x * n)
b = 1
For i = 1 To x
For j = 1 To n
Input #1, a(b)
b = b + 1
Next j
Next i
x = x - 1
For k = 1 To n
Print #2, a(k);
For xx = 1 To x
Print #2, a(k + n * xx);
Next xx
Print #2,
Next k
Close #2
Close #1
End
End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim ans()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x, y
ReDim ans(y, x)
For i = 1 To x
Line Input #1, a
b = Split(a, " ")
For j = 0 To UBound(b)
ans(j, i) = b(j)
Next
Next
For i = 0 To y - 1
For j = 1 To x
Print #2, ans(i, j) & " ";
Next
Print #2,
Next
Close
Close
End
End Sub
Private Sub Form_Load()
回覆刪除Dim A() As Integer
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, r, l
ReDim A(r * l)
For i = 1 To Val(r * l)
Input #1, n
A(i) = Val(n)
Next i
For i = 1 To Val(l)
s = 0
For j = 0 To Val(r) - 1
Print #2, A(i + s);
s = s + Val(l)
Next j
Print #2,
Next i
Close #2
Close #1
End
End Sub