Previous Questions Print cross chart time limit: 1.0s memory limit: 256.0MB
Title Address: http://lx.lanqiao.org/problem.page?gpid=T25
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. Code:
#include <stdio.h>int main () {char s[150][150]; int I, j, K; int n; scanf ("%d", &n); int center= (+ n-1) *4+1)/2; S[center][center]= ' $ '; for (j=center-2; j<=center+2; j + +) s[center][j]= ' $ '; for (i=center-2; i<=center+2; i++) s[i][center]= ' $ '; Tectonic center cross int dd=4; int ff=5; for (I=1; i<=n; i++) {int up=center-dd; For (j=center-((ff-1)/2); j<=center+ ((ff-1)/2); j + +) s[up][j]= ' $ '; int down=center+dd; For (j=center-((ff-1)/2); j<=center+ ((ff-1)/2); j + +) s[down][j]= ' $ '; int left=center-dd;//column for (k=center-((ff-1)/2); k<=center+ ((ff-1)/2); k++) s[k][left]= ' $ '; int right=center+dd; For (k=center-((ff-1)/2); k<=center+ ((ff-1)/2); k++) s[k][right]= ' $ '; dd+=2; ff+=4; }//Print four sidebar for (i=1; i<=n; i++) {//construct 1 points int A, b; a=center-i*2; S[a][a]= ' $ '; S[a-1][a]= ' $ '; S[a][a-1]= ' $ '; B=center+i*2; S[b][b]= ' $ '; S[b][b+1]= ' $ '; S[b+1][b]= ' $ '; S[a][b]= ' $ '; S[a-1][b]= ' $ '; S[a][b+1]= ' $ '; S[b][a]= ' $ '; S[b][a-1]= ' $ '; S[b+1][a]= ' $ '; } for (I=1; i<=9+ (n-1), i++) {for (j=1; j<=9+ (n-1); j + +) if (s[i][j]== ' $ ') printf ("$"); else printf ("."); printf ("\ n"); } return 0;}
A training print problem of Blue Bridge Competition "Construction + continuous construction + tectonic rule"