标签:des style blog color io os for 数据 div
1 4
1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7
#include <iostream> #include <string.h> #include <string> using namespace std; int main() { int t, n; int cnt; int a[15][15] ; int i, j; cin>>t; int x=0, y=0; while(t--) { memset(a, 0, sizeof(a)); cin>>n; a[0][0] = 1; cnt=1; x=0, y=0; while(cnt < n*n) { while(y+1<n && a[x][y+1]==0 ) { a[x][++y]=++cnt; } while(x+1<n && a[x+1][y]==0 ) { a[++x][y]= ++cnt; } while(y>0 && a[x][y-1]==0 ) { a[x][--y] = ++cnt; } while(x>0 && a[x-1][y]==0 ) { a[--x][y] = ++cnt; } } 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]<<‘\t‘; } } } return 0; }
标签:des style blog color io os for 数据 div
原文地址:http://www.cnblogs.com/yspworld/p/3967715.html