打印图形
打印如圖的圖形:
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; }待續(xù)。。。。。。
總結(jié)
- 上一篇: 嫦娥奔月(KMP,找循环节)及其扩展KM
- 下一篇: C. Three Parts of th