标签:
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 using namespace std; 6 const int maxn = 100; 7 int n; 8 int a[maxn][maxn]; 9 void draw() 10 { 11 memset(a, 0, sizeof(a)); 12 int t, tot=4*(n+1); 13 for(int i = 1; i <= n+1; i++) 14 { 15 t = i*2; 16 a[t][t] = 1; //a[0][2],a[1][2],a[2][2],a[2][1],a[2][0], 17 a[t][t-1] = a[t][t-2] = 1; 18 a[t-1][t] = a[t-2][t] = 1; 19 a[t][tot-t] = 1; //a[0][14],a[1][14],a[2][14],a[2][15],a[2][16] 20 a[t][tot-t+1] = a[t][tot-t+2] = 1; 21 a[t-1][tot-t] = a[t-2][tot-t] = 1; 22 a[tot-t][t] = 1; //a[14][0],a[14][1],a[14][2],a[15][2],a[16][2] 23 a[tot-t+1][t] = a[tot-t+2][t] = 1; 24 a[tot-t][t-1] = a[tot-t][t-2] = 1; 25 a[tot-t][tot-t] = 1; //a[14][14],a[14][15],a[14][16],a[15][14],a[16][14] 26 a[tot-t+1][tot-t] = a[tot-t+2][tot-t] = 1; 27 a[tot-t][tot-t+1] = a[tot-t][tot-t+2] = 1; 28 } 29 for(int i = 1; i <= n+1; i++) 30 { 31 t = i*2; 32 for(int j = t; j <= tot-t; j++) 33 { 34 //cout << t-2 << " " << tot-t+2 << endl; 35 a[j][t-2] = a[j][tot-t+2] = 1; 36 a[t-2][j] = a[tot-t+2][j] = 1; 37 } 38 39 } 40 } 41 void display() 42 { 43 for(int i = 0; i < 4*(n+1)+1; i++) 44 { 45 for(int j = 0; j < 4*(n+1)+1; j++) 46 { 47 if(a[i][j]) putchar(‘$‘); 48 else putchar(‘.‘); 49 } 50 putchar(‘\n‘); 51 } 52 } 53 int main() 54 { 55 scanf("%d", &n); 56 57 draw(); 58 59 display(); 60 61 return 0; 62 }
标签:
原文地址:http://www.cnblogs.com/LLGemini/p/4410286.html