1217: Print Hourglass

Source: Internet
Author: User

From: Co-worker Xuan OJ http://xcacm.hfut.edu.cn/problem.php?id=1217

Time limit: 1 Sec memory limit: MB

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

The input gives 1 positive integers n (<=1000) and a symbol in a row, with a space-delimited output that first prints out the largest hourglass shape consisting of a given symbol, and finally outputs the number of symbols left unused in a row.

Sample input

19 *

Sample output

The subject only needs a circular output to judge, the implementation process may have some detour.

1#include <stdio.h>2#include <iostream>3 using namespacestd;4 intUiintN)5    {6        if(n = =1)7            return 1;8        Else9            returnUI (n1)+4*n-2;Ten    } One   voidAlintNintNCharc) A   { -       inti; -       if(n = =1) the       { -            for(i =0; i < n-n; i++) -printf" "); -printf"%c", c); +printf"\ n"); -           return ;  +       }     A       Else at       { -            for(i =0; i < n-n; i++) -printf" "); -           for(i =0; I <2*n-1; i++) -printf"%c", c); -printf"\ n"); inAl (N, N-1, c);  -       } to   } +  voidPlintNintNCharc) -   { the       inti; *      if(n = =N) $       {Panax Notoginseng           for(i =0; I <2* n +1; i++) -printf"%c", c); theprintf"\ n"); +         return ;  A       } the       Else +       { -            for(i =0; i < n-n; i++) $printf" "); $            for(i =0; I <2* n +1; i++) -printf"%c", c); -printf"\ n"); thePL (N, n+1, c); -       }Wuyi   } the   voidPrintf_n (intNCharc) -   { Wu       intI, J; -  About        for(i = n; i >0; i--) $       { -           for(j = n-i; J >0; j--) -printf" "); -            for(j =0; J <2I1; J + +) Aprintf"%c", c); +printf"\ n");  the       } -       for(i =1; I < n; i++) $       { the            for(j = n-i; J >1; j--) theprintf" "); the            for(j =0; J <2* i +1; J + +) theprintf"%c", c); -printf"\ n");  in      } the   } the  intMainvoid) About   { the       CharC; the       intN, N, a, B; the      while(SCANF ("%d%c", &n, &c)! =EOF) +     { -n =1; the       while(N >= (a =UI (N)))Bayi      { then++; theb =A; -      } -n--; the printf_n (n, c); theprintf"%d\n"Nb); the     } the      return 0; -  } the  the /************************************************************** the problem:121794 user:2014217052 the language:c++ the Result: Correct the time:41 Ms98 memory:1504 KB About ****************************************************************/

1217: Print Hourglass

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.