#include <iostream>
using namespace std;
//向右移动0 向右上移动1 向下移动2 向左下移动3
int main()
{
int n,A[500][500];
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)cin >> A[i][j];
int row = 0, col = 0;
int temp=0;
while (row != n – 1 || col != n – 1)
{
cout << A[row][col] << ‘ ‘;
switch (temp)
{
case 0:
col++;
if (row == 0) temp = 3;
else temp = 1;
break;
case 1:
row–;
col++;
if (row == 0 && col != n – 1)temp = 0;
else if (col == n – 1)temp = 2;
else temp = 1;
break;
case 2:
row++;
if (col == 0)temp = 1;
else temp = 3;
break;
case 3:
row++;
col–;
if (col == 0 && row != n – 1) temp = 2;
else if (row == n – 1) temp = 0;
else temp = 3;
break;
}
}
cout << A[n – 1][n – 1];//保证最后一个元素输出来
}
CCF—Z字形扫描 20141202
原文作者:Z字形编排问题
原文地址: https://blog.csdn.net/zhaoshuling1109/article/details/78039368
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/zhaoshuling1109/article/details/78039368
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。