在原数组中修改的方法
先把矩形看作正方形,然后沿对角线对称一次,再左右对称一次
#include <iostream>
#include <cstring>
using namespace std;
const int N = 110;
int n, m, a[N][N], b[N][N];
int main()
{
cin >> n >> m;
for ( int i = 1; i <= n; i ++ )
for ( int j = 1; j <= m; j ++ )
cin >> a[i][j];
for ( int i = 1; i <= max(n, m); i ++ )
for ( int j = 1; j <= max(n, m); j ++ )
b[i][j] = a[j][i];
for ( int i = 1; i <= m; i ++ )
for ( int j = 1; j <= n; j ++ )
a[i][n + 1 - j] = b[i][j];
for ( int i = 1; i <= m; i ++ )
{
for ( int j = 1; j <= n; j ++ )
cout << a[i][j] << ' ';
cout << endl;
}
return 0;
}