hdu 2074
ps:WA了好多次...因為首先是n=1的情況,其次是中心花色和外花色,中心花色也有可能是最外層花色。。。。很無語。
然后就是格式問題咯。
代碼
#include "stdio.h" #include "string.h" void GG(int n,char a,char b); void pri(char a); int main(){int i,j,n,ncase=0;char a,b;while(~scanf("%d %c %c",&n,&a,&b)){if(ncase++) printf("\n");if(n==1){printf("%c\n",a);continue;} if((n/2+1)%2==0){GG(n,a,b);}else{GG(n,b,a);}}return 0; } void GG(int n,char a,char b){int i,j;for(i=1;i<=n/2+1;i++){if(i==1){printf(" ");for(j=1;j<=n-2;j++) pri(b);printf(" \n");}else{for(j=1;j<=n;j++){ if(j>=i && n-j+1>=i){if(i%2==0)pri(a);elsepri(b);}else{if(j%2==0){if(j==n){pri(a);printf("\n");continue;}pri(a);}else{if(j==n){pri(b);printf("\n");continue;}pri(b); }}}} }for(i=n-(n/2+1)+2;i<=n;i++){if(i==n){printf(" ");for(j=1;j<=n-2;j++) pri(b);printf(" \n");}else{for(j=1;j<=n;j++){ if(j<=i && n-i+1<=j){if(i%2==0)pri(a);elsepri(b);}else{if(j%2==0){if(j==n){pri(a);printf("\n");continue;}pri(a);}else{if(j==n){pri(b);printf("\n");continue;}pri(b); }}}} }} void pri(char a){printf("%c",a); }?
轉載于:https://www.cnblogs.com/sureli/p/5369898.html
總結
- 上一篇: Postgres数据库备份与还原命令
- 下一篇: 不生成新数组的迭代器方法:forEach