题目链接
- [旋转矩阵]
题解
- 经典题目了,选自 [PapaMelon 系统算法课程 - 基础版]。
- 二维数组看作一维,直接在一维数组上进行旋转,然后转为二维数组输出即可
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e6 + 5;
int n, m, K, a[N];
void solve() {
cin >> n >> m >> K;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i * m + j];
int tot = n * m;
K %= tot;
if (K) rotate(a, a + K, a + tot);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cout << a[i * m + j];
char c = j == m - 1 ? '\n' : ' ';
cout << c;
}
}
int main() {
int T;
cin >> T;
while (T--) solve();
return 0;
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦