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;
}