0
已解决
陈振轩
高级光能
高级光能
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
using namespace std;
int n, m, a[1050][1050], b[1050], cnt=1, c[1050][1050], j=1,k=1, cnt1=1;
void odto2d();
int main()
{
cin >> m >> n;
int ht = 1, hw = m, lw = n, lt = 1;
for (int i = 1; i <= m * n; i++) {
cin >> b[i];
}
odto2d();
while (cnt<=n*m) {
for (int i = lt; i <= lw; i++){
int j = 1, k=1;
b[cnt++] = c[ht][i];
//cnt++;
}
ht++;
if (cnt > m * n) break;
for (int i = ht; i <= hw; i++) {
int j = 1, k = 1;
b[cnt++] = c[i][lw];
//++cnt;
}
lw--;
if (cnt > m * n) break;
for (int i = lw; i >= lt; i--) {
int j = 1, k = 1;
b[cnt++] = c[hw][i];
//++cnt;
}
hw--;
if (cnt > m * n) break;
for (int i = hw; i >= ht; i--) {
int j = 1, k = 1;
b[cnt++] = c[i][lt] ;
// cnt++;
}
lt++;
if (cnt > m * n) break;
}
for (int i = 1; i <= m*n; i++) {
cout << b[i] << " ";
if(i/n>=1&&i%n==0)
cout << endl;
}
return 0;
}
void odto2d() {
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
c[i][j] = b[cnt1++];
}
}
}