#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
#define N 500
int a[N][N];
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> a[i][j];
}
}
for(int i = 0; i < 2*n-1; i++){
if(i < n)
{
if(i % 2 == 0)//偶数
{
for(int j = 0; j <= i; j++){
cout << a[i-j][j] <<" ";
}
}
else{//奇数
for(int j = i; j >= 0; j--){
cout << a[i-j][j] << " ";
}
}
}
else
{
if(i % 2 == 0)//偶数
{
for(int j = i - (n-1); j < n; j++){
cout << a[i-j][j] << " ";
}
}
else//奇数
{
for(int j = n-1; j >= i - (n-1);j--){
cout << a[i-j][j] << " ";
}
}
}
}
system("pause");
return 0;
}
解题思路: 需要仔细研究规律,细心一点就可以想出来