Lanqiao Cup Zhenti---Printing Cross

Lanqiao Cup Zhenti-Print Cross

Resource limitation
Time limitation: 1.0s Memory limitation: 256.0MB
Problem description
Xiao Ming designed a cross-shaped logo for an organization (not the Red Cross), as shown below:

..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..

The other party also needs to output the logo in the form of characters in the computer dos window, and can control the number of layers arbitrarily.

Input format
A positive integer n (n<30) indicates the number of layers of graphics required to be printed.
The output format
corresponds to the sign of the number of enclosing layers.
Sample input 1

1

Sample output 1

..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..

Sample input 2

3

Sample output 2

..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..

Tip
Please observe the sample carefully, paying particular attention to the number of periods and the output location. ,

The diagram draws on a picture of a big guy:
Insert picture description here
accept code :

#include<stdio.h>

int main()
{
    
    
    int n;
    scanf("%d",&n);
    int num=(n-1)*4+9;//n=1时,有9条边;n=3时,有17条边;

    char M[num+1][num+1];//使用二位数组存储

    for(int i=1;i<=num;i++){
    
    //刚开始全部初始化为'.'
        for(int j=1;j<=num;j++){
    
    
            M[i][j]='.';
        }
    }

    int core=(num/2+1);

    for(int i=-2;i<=2;i++){
    
    //中心的十字
        M[core+i][core]='$';
        M[core][i+core]='$';
    }

    int add=0;
    for(int i=core-2;i>=1;i-=2){
    
    //A区和C区
        for(int j=core;j>=core-add;j--){
    
    
            M[i][j]='$';
            M[j][i]='$';
        }
        add+=2;
    }

    for(int i=core;i>=2;i-=2){
    
    //B区,注意四个角不能有'$'
        M[i][i]='$';
        int j=i-1;
        while(j>=2&&M[i][j]!='$'){
    
    
            M[i][j]='$';
            j--;
        }
        j=i-1;
        while(j>=2&&M[j][i]!='$'){
    
    
            M[j][i]='$';
            j--;
        }
    }

    for(int i=1;i<=core;i++){
    
    //左右对折
        for(int j=1;j<=core;j++){
    
    
            M[i][2*core-j]=M[i][j];
        }
    }

    for(int i=core;i<=num;i++){
    
    //上下对折
        for(int j=1;j<=num;j++){
    
    
            M[i][j]=M[2*core-i][j];
        }
    }

    for(int i=1;i<=num;i++){
    
    //打印过程
        for(int j=1;j<=num;j++){
    
    
            printf("%c",M[i][j]);//注意不能有空格!否则就变成了正方形了!
        }
        printf("\n");
    }

    return 0;
}

Guess you like

Origin blog.csdn.net/timelessx_x/article/details/114491231