题目描述
代码描述
#include<iostream>
using namespace std;
int main() {
int n;
cin>>n;
int a[n][n];
for(int i; i<n; i++) {
for(int j=0; j<n; j++) {
cin>>a[i][j];
}
}
int i=0,j=0;
int t=0;
if(n%2==0)
t=n;
else
t=n-1;
cout<<a[i][j]<<" ";
int c=0;
while(t>0) {
if(i==0&&c==0&&j<n-1) {
j++;
t--;
c=1;
cout<<a[i][j]<<" ";
}
else if(i==n-1&&c==0&&j<n-1) {
j++;
t--;
c=2;
cout<<a[i][j]<<" ";
}
else if(j==0&&c==0&&i<n-1) {
i++;
c=2;
cout<<a[i][j]<<" ";
}
else if(j==n-1&&c==0&&i<n-1) {
i++;
c=1;
cout<<a[i][j]<<" ";
}
else if(c==1&&i<n-1&&j>0) {
i++;
j--;
cout<<a[i][j]<<" ";
}
else if(c==2&&j<n-1&&i>0){
i--;
j++;
cout<<a[i][j]<<" ";
}
else {
c=0;
}
}
cout<<endl;
}