标签:
3
7 8 1
6 9 2
5 4 3
<span style="font-size:18px;">#include<iostream> #include<algorithm> #include<stdio.h> using namespace std; int main() { int n,i,j,t,x,y; while(cin>>n) { int a[100][100]={0}; t=a[0][n-1]=1; x=0; y=n-1; while(t<n*n) { while(x+1<n&&a[x+1][y]==0) a[++x][y]=++t; while(y-1>=0&&a[x][y-1]==0) a[x][--y]=++t; while(x-1>=0&&a[x-1][y]==0) a[--x][y]=++t; while(y+1<n&&a[x][y+1]==0) a[x][++y]=++t; } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(j==n-1) cout<<a[i][j]<<endl; else cout<<a[i][j]<<" "; } } } return 0; }</span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/phytn/article/details/46763431