交换后转置
将第1行和最后一行,第二行和倒数第二行,…, 互换
互换完再转置就得到答案
#include <iostream>
#include <vector>
using namespace std;
const int N = 110;
vector<vector<int>> a(N, vector<int>(N,0));
vector<vector<int>> b(N, vector<int>(N,0));
int main()
{
int n, m; cin >> n >> m;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) cin >> a[i][j];
}
for(int i = 1; i <= n / 2; ++i) {
swap(a[i], a[n-i+1]);
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
b[j][i] = a[i][j];
}
}
for(int i = 1; i <= m; ++i) {
for(int j = 1; j <= n; ++j)
cout << b[i][j] << " ";
cout << endl;
}
return 0;
}