标签:
旋转数阵
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1477 Solved: 102
3 4
1 2 3 8 9 4 7 6 5 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7
1 #include<stdio.h> 2 #include<string.h> 3 const int M = 11 ; 4 int a[M][M] ; 5 int main () 6 { 7 int n , x , y , tot = 0 ; 8 while (~ scanf ("%d" , &n) ) { 9 memset (a , 0 , sizeof(a)) ; 10 tot = a[x = 0][y = 0] = 1 ; 11 while (tot < n * n) { 12 while (y + 1 < n && !a[x][y + 1]) a[x][++y] = ++tot ; 13 while (x + 1 < n && !a[x + 1][y]) a[++x][y] = ++tot ; 14 while (y - 1 >= 0 && !a[x][y - 1]) a[x][--y] = ++tot ; 15 while (x - 1 >= 0 && !a[x - 1][y]) a[--x][y] = ++tot ; 16 } 17 for (x = 0 ; x < n ; x++) { 18 for (y = 0 ; y < n ; y++) { 19 printf ("%3d" , a[x][y]) ; 20 } 21 printf ("\n") ; 22 } 23 } 24 return 0 ; 25 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4391680.html