长时间没写,都不会了
输出1
121
12321
121
1
[ 本帖最后由 bccn_0934 于 2011-7-6 00:34 编辑 ]
#include <stdio.h> #include <string.h> char a[30][30] = {0}; void draw(int n) { int i,j,k; for(i = 1;i<=2*n-1;i++) { char x = 'A'; char temp = 0; for(j = 1;j<=2*n-1;j++) { if(i<=n) { if(j>=n-(i-1) && j<=n) { a[i][j] = x++; if(j == n) temp = a[i][n]; } else if(j>n && j<=n+(i-1)) { a[i][j] = --temp; } else if(j<=n) a[i][j] = ' '; } else { int buf = i - 2*(i-n); if(j>=n-(buf-1) && j<=n) { a[i][j] = x++; if(j == n) temp = a[i][n]; } else if(j>n && j<=n+(buf-1)) { a[i][j] = --temp; } else if(j<=n) a[i][j] = ' '; } } } } int main() { int i,j,k; int n,m = 1; while(EOF != scanf("%d",&n)) { if(n>26 || n<-26) { printf("No image!\n"); continue; } int temp = n; if(n<0) n*=-1; memset(a,0,sizeof(a)); printf("Case %d: n=%d\n",m++,temp); draw(n); for(i = 1;i<=2*n-1;i++) { for(j = 1;j<=2*n-1;j++) { printf("%c",a[i][j]); } printf("\n"); } printf("\n"); } return 0; }