题目:输出一个叠筐图,一个个大小差一圈的叠筐图,使得从上往下看时,边框花色交替
如下:当输入5 @ W
输出为:
5 @ W
@@@
@WWW@
@W@W@
@WWW@
@@@
实现代码:
#include <stdio.h>
int main(int argc, char *argv[])
{
int outPutBuf[82][82];
char a,b;
int n;
bool firstCase=true;
while(scanf("%d %c %c",&n,&a,&b)==3){
if(firstCase==true) firstCase=false;
else printf("\n");
for(int i=1,j=1;i<=n;i+=2,j++){
int x=n/2+1,y=x;
x-=j-1;y-=j-1;
char c=j%2==1?a:b;
for(int k=1;k<=i;k++){
outPutBuf[x+k-1][y]=c;
outPutBuf[x][y+k-1]=c;
outPutBuf[x+i-1][y+k-1]=c;
outPutBuf[x+k-1][y+i-1]=c;
}
}
if(n!=1){
outPutBuf[1][1]=' ';
outPutBuf[n][1]=' ';
outPutBuf[1][n]=' ';
outPutBuf[n][n]=' ';
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
printf("%c",outPutBuf[i][j]);
}
printf("\n");
}
}
return 0;
}
测试输出:
9
@ *
@@@@@@@
@*******@
@*@@@@@*@
@*@***@*@
@*@*@*@*@
@*@***@*@
@*@@@@@*@
@*******@
@@@@@@@