问题描述
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
输入格式
一个正整数 n (n<30) 表示要求打印图形的层数。
输出格式
对应包围层数的该标志。
样例输入1
1
样例输出1
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
样例输入2
3
样例输出2
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
提示
请仔细观察样例,尤其要注意句点的数量和输出位置。
示例代码:
1 #include <stdio.h> 2 #include <string.h> 3 4 int n = 0 , len = 5; 5 char arr[125+1][125+1] ; 6 7 void dp(int x) 8 { 9 int i,j,k; 10 if (x <= 2*n) 11 { 12 if (x%2 == 0) 13 { 14 i = x+1 , j = len-x; 15 arr[i][i] = arr[x][i] = arr[i][x] = '$'; /*左上*/ 16 arr[i][j] = arr[x][j] = arr[i][j+1] = '$'; /*右上*/ 17 arr[j][i] = arr[j+1][i] = arr[j][x] = '$'; /*左下*/ 18 arr[j][j] = arr[j+1][j] = arr[j][j+1] = '$';/*右下*/ 19 } 20 else 21 { 22 for (i = x+2 ; i <= len-x-1 ; i ++) 23 { 24 arr[x][i] = arr[len+1-x][i] = '$';/*上下边*/ 25 arr[i][x] = arr[i][len+1-x] = '$';/*左右边*/ 26 } 27 } 28 dp(x+1); 29 } 30 return ; 31 } 32 33 int main(void) 34 { 35 36 int i,j; 37 memset(arr,'.',sizeof(arr)); 38 scanf("%d",&n); 39 len += 4*n; 40 41 /*内部的十字*/ 42 for (i = len/2+1 , j = 2*n+1 ; j <= len-2*n ; j ++) 43 arr[i][j] = '$'; 44 for (j = len/2+1 , i = 2*n+1 ; i <= len-2*n ; i ++) 45 arr[i][j] = '$'; 46 47 dp(1);/*外圈*/ 48 49 for (i = 1 ; i <= len ; i ++) 50 { 51 for (j = 1 ; j <= len ; j ++) 52 { 53 printf("%c",arr[i][j]); 54 } 55 printf("\n"); 56 } 57 return 0; 58 }