PAT1027. Print Hourglass (20)

Source: Internet
Author: User

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
IDEA: The format error is many, should not print the space not to print
1#include <stdio.h>2#include <string.h>3 Charpattern[1010][1010];4 intMainintargcChar**argv)5 {6memset (Pattern,' ',sizeof(Char)*1010*1010);7     intsum;8     CharZifu;9scanf"%d%c",&sum,&Zifu);Ten     intReminder; One     if(sum>=7) A     { -         //Rol needs to be recalculated -         intRol=0; the          while(true) -         { -             if((rol*rol+2*rol) *2+1>sum) -                 Break; +             Else -rol++; +         } Arol--; at     //printf ("%dfds", rol); -reminder=sum-(rol*rol+2*rol) *2-1; -         intfirlas=2*rol+1; -         //to assign a value -          for(intI=0; i<rol;i++) -         { in              for(intj=i;j<firlas-i;j++) -            { topattern[i][j]=Zifu; +            }     -         }  the        //Middle *pattern[rol][firlas/2]=Zifu; $           //below, print from bottom to topPanax Notoginseng          for(inti=rol*2; i>rol;i--) -         { the              for(intj=2*rol-i;j<firlas-(2*rol-i); j + +) +pattern[i][j]=Zifu; A         }  the        //to print above +          for(intI=0; i<rol;i++) -         { $              for(intj=0; j<firlas-i;j++) $             { -printf"%c", Pattern[i][j]); -              } thePutchar ('\ n');  -         } Wuyi          for(inti=rol;i<2*rol+1; i++) the         { -              for(intj=0; j<firlas/2+i-rol+1; j + +) Wu             { -printf"%c", Pattern[i][j]); About             } $Putchar ('\ n'); -         } -        } -        Else A        { +reminder=sum-1; theprintf"%c\n", Zifu); -     } $printf"%d\n", reminder); the      the     return 0; the}
View Code

PAT1027. Print Hourglass (20)

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.