题目链接
- [旋转矩阵]
题解
- 经典题目了,选自 [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人點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦