Problem Description
已知一(m x n)矩陣A,我們常常需要用到另一個將A中之行與列調換的矩陣。這個動作叫做矩陣的翻轉。舉例來說,若
A = [ 3 1 2 ] 8 5 4
則
AT = [ 3 8 ] 1 5 2 4
Input Format
第一行會有兩個數字,分別為 列(row)<100 和 行(column)<100,緊接著就是這個矩陣的內容
Output Format
直接輸出翻轉後的矩陣
Sample Input
2 3 3 1 2 8 5 4
Sample Output
3 8 1 5 2 4
-----*Problem from【ZeroJudge, An Online Judge System For Beginners】
My Answer
| 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. | #include<iostream> using namespace std; int main(void) { int row, column; while(cin>>column>>row){ int a[column][row]; for(int j=0; j<column; ++j){ for(int i=0; i<row; ++i){ cin>>a[j][i]; } } for(int j=0; j<row; ++j){ for(int i=0; i<column; ++i){ cout<<a[i][j]<<" "; } cout<<endl; } } return 0; } |
