1027. Print Hourglass (20) time limit MS Memory limit 32000 KB code length limit 8000 B procedure StandardAuthor Chen, Yue
The subject asks you to write a program to print the given symbol into an hourglass shape. For example, given 17 "*", require printing in the following format
***** *** * ********
The so-called "hourglass shape" refers to the output of an odd number of symbols per line, the line symbol center alignment, the adjacent two lines sign number difference 2, the number of symbols from large to small order descending to 1, and then from small to large order increment;
Given any n symbols, it is not always possible to form an hourglass exactly. Require that the printed hourglass be able to use as many symbols as possible.
Input format:
The input gives 1 positive integers n (<=1000) and a symbol in one line, separated by a space in the middle.
Output format:
The largest hourglass shape consisting of a given symbol is printed first, and the number of symbols left unused in a row is finally output.
Input Sample:
19 *
Sample output:
* ********2
1#include <iostream>2#include <cmath>3 4 using namespacestd;5 6 intMain ()7 {8 intN;9 CharC;TenCIN >> N >>C; One intK = sqrt ((N +1) /2); A for(inti =1; I <= K; i++) - { - for(intj =1; J < I; J + +) the { -cout <<" "; - } - for(intj =2* (k-i) +1; J >=1; j--) + { -cout <<C; + } Acout <<Endl; at } - for(inti =1; I <= K-1; i++) - { - for(intj =1; J <= K-i-1; J + +) - { -cout <<" "; in } - for(intj =1; J <=2* i +1; J + +) to { +cout <<C; - } thecout <<Endl; * } $cout << N +1-2* K*k <<Endl;Panax Notoginseng return 0; -}
PAT (Basic level) practise (Chinese) 1027. Print Hourglass (20)