#include<stdio.h> int i,j; int a[100][100]; void print(int n,int depth) { if(n == depth) { a[n][n] = depth+1; return ; } for(i = depth;i<=n;i++) a[depth][i] = a[n][i] = depth+1; for(i = depth;i<=n;i++) a[i][depth] = a[i][n] = depth+1; print(n-1,depth+1); } int main() { int t; while(~scanf("%d", &t)) { if(!(t&0x01))continue; print(t-1,0); for(i = 0;i<t;i++) { for(j = 0;j<t;j++) printf("%2d ",a[i][j]); printf("\n"); } } return 0; }
#include<stdio.h> int i,j; int a[100][100]; void print(int n,int depth) { if(n+1 == depth)return ; if(n == depth) { a[n][n] = depth+1; return ; } for(i = depth;i<=n;i++) a[depth][i] = a[n][i] = depth+1; for(i = depth;i<=n;i++) a[i][depth] = a[i][n] = depth+1; print(n-1,depth+1); } int main() { int t; while(~scanf("%d", &t)) { print(t-1,0); for(i = 0;i<t;i++) { for(j = 0;j<t;j++) printf("%2d ",a[i][j]); printf("\n"); } } return 0; }
#include <stdio.h> #define MIN(a, b) ((a) < (b) ? a : b) int min4(int a, int b, int c, int d) { int min = 0; min = MIN(a, b); min = MIN(min, c); min = MIN(min, d); return min; } int main(void) { int top, left, bottom, right, width, i, j; scanf("%d", &width); for (i = 0; i < width; ++i) { for (j = 0; j < width; ++j) { top = i + 1; left = j + 1; bottom = width - i; right = width - j; printf("%-3d", min4(top, left, bottom, right)); } printf("\n"); } return 0; }我也献丑啦!!!!