Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
119652 | 胡海峰老师 | 数组转置 | C++ | Accepted | 1 MS | 264 KB | 748 | 2025-05-18 11:01:07 |
#include <iostream> using namespace std; int main() { int n = 3; int a[3][3]; int b[3][3]; // 输入矩阵a for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } // 正确转置:将a转置到b for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { b[i][j] = a[j][i]; // 将a的列变为b的行 } } // 输出转置后的矩阵b(每行最后无空格) for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << b[i][j]; if (j < n - 1) { cout << " "; } } cout << endl; } return 0; }