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: $$$$$$$$$$$$$..
.. $...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
.. $...........$..
.. $$$$$$$$$$$$$..
Idea: The most important thing to solve this kind of problem is to find the law, we found that only 1/4 of the graph is required, the other places are symmetrical
So the AC code:
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream>using namespace Std;char Str[150][150];int Main () {int n; Freopen ("In.cpp", "R", stdin); Freopen ("Out.cpp", "w", stdout); while (cin>>n) {str[1][1]=str[2][1]=str[2][2]= '. '; int mid= (4*n+5)/2+1; for (int i=3; i<=mid; i++) {if ((i-3)%2==0) {int J; for (j=1; j<=i-3; J + +) {if (j%2==0) str[i][j]= '. '; Else str[i][j]= ' $ '; cout<<str[i][j]; } for (; j<=i; j + +) {str[i][j]= ' $ '; cout<<str[i][j]; }//cout<<endl; } else {int J; for (j=1; j<=i-2; J + +) { if (j%2==0) str[i][j]= '. '; Else str[i][j]= ' $ '; cout<<str[i][j]; } for (; j<=i; j + +) {str[i][j]= '. '; cout<<str[i][j]; }//cout<<endl; }} for (int i=1, i<=mid; i++) {for (int j=i+1; j<=mid; J + +) { Str[i][j]=str[j][i]; cout<<str[i][j]; }//cout<<endl; }/* for (int i=1;i<=mid;i++) {for (int j=1;j<=mid;j++) {cout<& LT;STR[I][J]; } cout<<endl; }*/for (int i=1, i<=mid; i++) {for (int j=mid+1; j<= (4*n+5); j + +) { STR[I][J]=STR[I][4*N+5-J+1]; cout<<4*n+5-j+1<< ""; cout<<str[i][j]; }//cout<<endl; } for (int i=1; i<=mid; i++) {for (int j=1; j<= (4*n+5); j + +) Cout<<str I [j]; cout<<endl; } for (int i=mid-1, i>=1; i--) {for (int j=1; j<= (4*n+5); j + +) cout<<st R[I][J]; cout<<endl; }} return 0;}
Blue Bridge Cup print cross chart