打印图形
程序员文章站
2024-03-15 08:26:47
...
打印如图的图形:
0 * 1 ** * 2 **** * * ** * 3 ******** * * * * ****** * * * **** * * ** * 4 **************** * * * * * * * * ************** * * * * * * * ************ * * * * * * ********** * * * * * ******** * * * * ****** * * * **** * * ** *
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
char maze[1100][1100];
int n;
void init(){
int t = 1 << n, k = 1 << n, m = 0;
int num = t, cnt = 0;
while(k){
cnt++;
int val = 0;
for(int j = 0; j < 2; j++){
for(int i = 0; i < num; i++){
if(j == 1&&i%2) maze[j+m][i] = ' ';
else maze[j+m][i] = '*';
}
}
num -= 2;k -=2;
m = m+2;
}
}
int main()
{
while(scanf("%d", &n) != EOF){
if(n == 0) printf("*\n");
else{
init();
int t = 1 << n, k = 1 << n;
for(int i = 0; i < t; i++){
printf("%s\n\n", maze[i]);
}
}
}
return 0;
}
待续。。。。。。
上一篇: . Smoothing Images
下一篇: compare