AcWing 3208. Z字形扫描
原题链接
简单
作者:
吴鑫
,
2021-02-16 11:04:56
,
所有人可见
,
阅读 344
#include<iostream>
using namespace std;
const int N=510;
int p[N][N];
int n;
int main(){
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>p[i][j];
int x=0,y=0;
cout<<p[x][y]<<" ";
while(x!=n-1||y!=n-1){
if(y+1<n) {
cout<<p[x][++y]<<" ";
if(x+1<n&&y-1>=0)
while(x+1<n&&y-1>=0) cout<<p[++x][--y]<<" ";
else if(y+1<n&&x-1>=0)
while(y+1<n&&x-1>=0) cout<<p[--x][++y]<<" ";
}
if(x+1<n){
cout<<p[++x][y]<<" ";
if(x+1<n&&y-1>=0)
while(x+1<n&&y-1>=0) cout<<p[++x][--y]<<" ";
else if(y+1<n&&x-1>=0)
while(y+1<n&&x-1>=0) cout<<p[--x][++y]<<" ";
}
}
return 0;
}