#41313: c++解題方式


spark960513@gmail.com (Sparkkk_)

學校 : 臺北市立成功高級中學
編號 : 204599
來源 : [124.218.194.42]
最後登入時間 :
2024-10-03 02:19:06
a015. 矩陣的翻轉 | From: [124.218.194.42] | 發表日期 : 2024-07-17 02:16

簡單一點的方法,直接設置兩個矩陣(100x100)然後交換就可以了。

#include <iostream>

using namespace std;
int main()
{
int row, column;
int matrixA[100][100] = {0}, matrixB[100][100] = {0};

while(cin>>row>>column)
{
    //matrix init
    for(int i = 0; i < row; ++i)
    {
        for(int j = 0; j < column; ++j)
        {
            cin>>matrixA[i][j];
        }
    }

    //flip
    for(int i = 0; i < row; ++i)
    {
        for(int j = 0; j < column; ++j)
        {
            matrixB[j][i] = matrixA[i][j];
        }
    }

    
    //output
    for(int i = 0; i < column; ++i)
    {
        for(int j = 0; j < row; ++j)
        {
            cout<matrixB[i][j];
            if(j != row - 1 ) cout<<" ";
        }
        cout<endl;
    }
}
    return 0;
}

 
ZeroJudge Forum