PAT b 1027 Print hourglass (c + + edition)

Source: Internet
Author: User

1027. Print Hourglass (20) time limit MS Memory limit 65536 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 //1027.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6 7 using namespacestd;8 9 intMain ()Ten { One     intn, N; A     CharC; -  -CIN >>N; the GetChar (); -CIN >>C; -  -      for(n =1;2* N*n-1<= N; ++n); +  ---N; +  A      for(inti = n; i >0; --i) at     { -          for(intj =0; J < N-i; ++j) -cout <<" "; -  -          for(intj =0; J <2I1; ++j) -cout <<C; in  -cout <<Endl; to     } +  -      for(inti =2; I <= N; ++i) the     { *          for(intj =0; J < N-i; ++j) $cout <<" ";Panax Notoginseng  -          for(intj =0; J <2I1; ++j) thecout <<C; +  Acout <<Endl; the     } +  -cout << N-2* N*n +1<<Endl; $  $     return 0; -}

PAT b 1027 Print hourglass (c + + edition)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.