Previous Questions Print cross chart time limit: 1.0s memory limit: 256.0MB
Problem description
Xiao Ming designed a cross-shaped logo for an institution (not the Red Cross), as shown below:
.. $$$$$$$$$$$$$..
.. $...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
.. $...........$..
.. $$$$$$$$$$$$$..
The other side also needs to be in the Computer DOS window in the form of characters to output the flag, and can control the number of layers.
Input format a positive integer n (n<30) indicates the number of layers required to print the graphic. The output format corresponds to this flag that encloses the number of layers. Example input 11 sample Output 1: $$$$$..
.. $...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
.. $...$..
.. $$$$$.. Example input 23 sample Output 2: $$$$$$$$$$$$$..
.. $...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
.. $...........$..
.. $$$$$$$$$$$$$.. Tip Be careful to look at the sample, especially the number of periods and the output location.
This problem looked at characters for a long time did not find the law, can only be drawn out of the graph to find symmetry,
My idea is to simulate the figure on the left 1/8, and use the symmetry of the remaining 1/8,1/4,1/2 to simplify the amount of code
#include <iostream>#include<cstdio>using namespacestd;inta[ -][ -];intMain () {intn =0, cen =0; while(SCANF ("%d", &n) = =1) {cen=2* (n+1); A[cen][cen]=1; A[cen][cen-1] = a[cen][cen-2] =1; for(inti =2; I <= CEN-2; i = i+2) { for(intj = i-2; J <= I; J + +) A[i][j]=1; for(intm = I,n = i-2; M <= Cen; m++) A[m][n]=1; }//left 1/8 Graphics for(inti =0; I <= cen; i++) for(intj =0; J <= I; J + +) A[j][i]=A[i][j]; for(inti =0; I <= cen; i++) for(intj =0; J <= Cen; J + +) a[i][2*CEN-J] =A[i][j]; for(intj =0; J <=2*cen; J + +) for(inti =0; I <= cen; i + +) a[2*CEN-I][J] =A[i][j]; for(inti =0; I <=2*cen; i + +) { for(intj =0; J <=2*cen; J + +) { if(A[i][j] = =1) printf ("$"); Elseprintf ("."); } printf ("\ n"); } } return 0;}
Blue Bridge cup-print cross chart