(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;
}