#include <iostream>
#include <vector>
using namespace std;
int n;
int main() {
cin>>n;
int a[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin>>a[i][j];
}
}
vector<int>vec;
int i = 0,j = 0;
int k = 2*n - 1;
while (k--){
if(k % 2 == 0){
do {
vec.push_back(a[i--][j++]);
} while ( j<n && i>=0);
if (i < 0 && j < n){
i++;
}else{
i += 2;
j--;
}
}
else
{
do {
vec.push_back(a[i++][j--]);
} while ( i<n && j>=0);
if (j < 0 && i < n){
j++;
}else{
j += 2;
i--;
}
}
}
for (int l = 0; l < vec.size(); ++l) {
cout<<vec[l]<<" ";
}
return 0;
}
cspZ字形扫描
最新推荐文章于 2024-11-04 23:11:51 发布