临时备忘
#include <iostream>
int main()
{
const int rows = 3; // 行
const int cols = 8; // 列
// 假设原矩阵是通过一维数组表示 3 * 8
int matrix[rows * cols] = {11,12,13,14,15,16,17,18,
21,22,23,24,25,26,27,28,
31,32,33,34,35,36,37,38};
// 新矩阵的大小是 8 * 3
const int brows=8;
const int bcols=3;
int new_matrix[brows * bcols] = {0};
// 打印矩阵
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
std::cout << matrix[i * cols + j] << " ";
}
std::cout << std::endl;
}
// 填充新矩阵
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
new_matrix[j * rows + (rows - 1 - i)] = matrix[i * cols + j];
}
}
// 打印新矩阵
for (int i = 0; i < brows; i++) {
for (int j = 0; j < bcols; j++) {
std::cout << new_matrix[i * bcols + j] << " ";
}
std::cout << std::endl;
}
return 0;
}