201412-2-Z字形扫描

(http://115.28.138.223/view.page?gpid=T20)

#include<stdio.h>
int main()
{
    int i,j,n,x,y;
    scanf("%d",&n);
    int c[n][n];    
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            scanf("%d",&c[i][j]);   
    printf("%d ",c[x=0][y=0]);
    int vis=1;
    while(vis<n*n)
    {
        if(y+1<n)
            {printf("%d ",c[x][++y]);vis++;}//向右 
        else
            {printf("%d ",c[++x][y]);vis++;}//向下 
        while(y>0&&x<n-1) 
        {
            printf("%d ",c[++x][--y]);
            vis++;
        }
        if(x+1<n)
            {printf("%d ",c[++x][y]);vis++;}//向下 
        else
            {printf("%d ",c[x][++y]);vis++;}//向右 
        while(x>0&&y<n-1)
        {
            printf("%d ",c[--x][++y]);
            vis++;
        }       
    }
    return 0;
} 
    原文作者:Z字形编排问题
    原文地址: https://blog.csdn.net/leo__ares/article/details/52748242
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞