AcWing 3174. 旋转
原题链接
简单
作者:
王小强
,
2021-03-21 10:07:56
,
所有人可见
,
阅读 428
找规律模拟(非原地算法)
#include <iostream>
#include <vector>
using namespace std;
int m, n;
int main(int argc, char** argv) {
cin >> m >> n;
vector<vector<int>> grid(m, vector<int>(n));
for (int y = 0; y < m; ++y)
for (int x = 0; x < n; ++x) cin >> grid[y][x];
vector<vector<int>> matrix(n, vector<int>(m));
for (int y = 0; y < m; ++y)
for (int x = 0; x < n; ++x)
matrix[x][m - 1 - y] = grid[y][x];
for (int y = 0; y < n; ++y) {
for (int x = 0; x < m; ++x)
cout << matrix[y][x] << ' ';
cout << endl;
}
return 0;
}