10:矩阵转置

10:矩阵转置



总时间限制: 
1000ms 
内存限制: 
65536kB
描述

输入一个n行m列的矩阵A,输出它的转置AT

输入
第一行包含两个整数n和m,表示矩阵A的行数和列数。1 <= n <= 100,1 <= m <= 100。
接下来n行,每行m个整数,表示矩阵A的元素。相邻两个整数之间用单个空格隔开,每个元素均在1~1000之间。
输出
m行,每行n个整数,为矩阵A的转置。相邻两个整数之间用单个空格隔开。
样例输入
3 3
1 2 3
4 5 6
7 8 9
样例输出
1 4 7
2 5 8
3 6 9
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
#define MAX 1000001

int a[1001][1001];
int b[1001][1001];
int c[1001][1001];
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, k;
    cin >> n >> k;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k; j++) {
            cin >> a[i][j];
            b[j][i] = a[i][j];
        }
    }
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= n; j++) {
            if(j != 1) {
                cout << " " << b[i][j] ;
            } else {
                cout << b[i][j] ;
            }
        }
        cout << endl;
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值