You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
668 B
54 lines
668 B
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
int main() {
|
|
int n,m,j,i,x,y;
|
|
scanf("%d %d",&n,&m);
|
|
int a[n][m];
|
|
int b[n*m];
|
|
for(i=0; i<n; i++)
|
|
for(j=0; j<m; j++)
|
|
scanf("%d",&a[i][j]);
|
|
|
|
x=0;
|
|
y=0;
|
|
int k=0;
|
|
while(k<n*m) {
|
|
while(a[x][y]!=-1&&x<n) {
|
|
b[k]=a[x][y];
|
|
a[x][y]=-1;
|
|
x++;
|
|
k++;
|
|
}
|
|
x--;
|
|
y++;
|
|
while(a[x][y]!=-1&&y<m) {
|
|
b[k]=a[x][y];
|
|
a[x][y]=-1;
|
|
y++;
|
|
k++;
|
|
}
|
|
y--;
|
|
x--;
|
|
while(a[x][y]!=-1&&x>=0) {
|
|
b[k]=a[x][y];
|
|
a[x][y]=-1;
|
|
x--;
|
|
k++;
|
|
}
|
|
x++;
|
|
y--;
|
|
while(a[x][y]!=-1&&y>=0) {
|
|
b[k]=a[x][y];
|
|
a[x][y]=-1;
|
|
y--;
|
|
k++;
|
|
}
|
|
y++;
|
|
x++;
|
|
}
|
|
for(i=0; i<k; i++)
|
|
printf("%d ",b[i]);
|
|
return 0;
|
|
}
|