首页 > 代码库 > zoj3839-Poker Face
zoj3839-Poker Face
#include<cstdio>
int n;
void P(int i,int j,int n,int f){
if(i==n){
for(int k=1;k<=n;k++)printf("*");
if(!f) puts("");
}
else if(i==1){
for(int k=1;k<=n;k++)printf("*");
if(!f){puts("");
P(i+1,1,n,f);}
else printf("*");
}
else if(i==n/8+1||i==n/4+n/8+1){
printf("*");
for(int k=2;k<n/8+1;k++)printf(" ");
for(int k=n/8+1;k<n/4+n/8+1;k++)printf("*");
for(int k=n/4+n/8+1;k<n/8+n/2+1;k++)printf(" ");
for(int k=n/8+n/2+1;k<=3*n/4+n/8;k++)printf("*");
for(int k=3*n/4+n/8+1;k<n;k++)printf(" ");
if(!f){puts("*");
// (j>n/8+1&&j<n/4+n/8||j>n/8+n/2+1&&j<n/8+3*n/4)
P(i+1,1,n,f);}
else printf("*");
}
else if(i>n/8+1&&i<n/4+n/8+1){
printf("*");
for(int k=2;k<n/8+1;k++)printf(" ");printf("*");
for(int k=n/8+2;k<n/4+n/8;k++)printf(" ");printf("*");
for(int k=n/4+n/8+1;k<n/8+n/2+1;k++)printf(" ");printf("*");
for(int k=n/8+n/2+2;k<3*n/4+n/8;k++)printf(" ");printf("*");
for(int k=3*n/4+n/8+1;k<n;k++)printf(" ");
if(!f){
puts("*");
// (j>n/8+1&&j<n/4+n/8||j>n/8+n/2+1&&j<n/8+3*n/4)
P(i+1,1,n,f);}
else printf("*");
}
// else if(i>=n/8+1&&i<=n/8+n/4+1&&(j==n/8+1||j==n/8+n/4||j==n/8+n/2+1||j==n/8+3*n/4))printf("*"),P(i,j+1,n);
else if(i==n/2+1){
printf("*");
for(int k=2;k<n/4+1;k++)printf(" ");
for(int k=n/4+1;k<=n-n/4;k++)printf("*");
for(int k=n-n/4+1;k<n;k++)printf(" ");
if(!f){puts("*");
P(i+1,1,n,f);}
else printf("*");
}
else if(i>n/2+1&&i<n){
if(n==8){
if(i==5)printf("* **** *");
else printf("* * * *");
if(!f){puts("");
P(i+1,1,n,f);}
}
//if(j>=n/4+1&&j<=n-n/4)printf("*"),P(i,j+1,n);
else {
printf("*");
for(int k=2;k<n/4+1;k++)printf(" ");
P(n-i+1,1,n/2,1);
for(int k=n-n/4+1;k<n;k++)printf(" ");
if(!f){puts("*");
P(i+1,1,n,0); }
else printf("*");
}
}
else {
printf("*");
for(int k=2;k<=n-1;k++)printf(" ");
if(!f){puts("*");
P(i+1,1,n,f);}
else printf("*");
}
return ;
}
int main(){
while(scanf("%d",&n)&&n>=8){
P(1,1,n,0);
puts("");
}
}
zoj3839-Poker Face