文章
79
粉丝
221
获赞
46
访问
202.1k
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int** a = new int* [n];
for (int i = 0; i < n; i++) {
a[i] = new int[n];
for (int j = 0; j < n; j++)
cin >> a[i][j];
}
for (int i = 0; i <n/2; i++) {
for (int j = 0; j < n; j++)
swap(a[i][j], a[n - i - 1][j]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << a[i][j] << " ";
cout << endl;
}
return 0;
}
需要注意:只看行翻转,i<n/2,且交换a[i][j]与a[n - i - 1][j]的值即可
登录后发布评论
暂无评论,来抢沙发