输出时的顺序按照从右往左,从上往下即可。如下图:
#include <iostream>
using namespace std;
const int N = 1010;
int n, m;
int a[N][N];
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i ++ ) //按顺序输入
for (int j = 0; j < m; j ++ )
cin >> a[i][j];
for (int j = m - 1; ~j; j -- ) //从右往左,~j 表示 j >= 0
{
for (int i = 0; i < n; i ++ ) //从上往下
cout << a[i][j] << ' ';
cout << endl;
}
}
该题还有一子姊妹题,即顺时针旋转90度: 3174. 旋转