Mario

tl;dr

Implement a program that prints out a half-pyramid of a specified height, per the below.

아래와 같이 지정된 높이의 피라미드 반쪽을 출력하는 프로그램을 작성하시오

$ ./mario
Height: 5
    ##
   ###
  ####
 #####
######

$ ./mario
Height: 3
  ##
 ###
####

Background

Toward the end of World 1-1 in Nintendo’s Super Mario Brothers, Mario must ascend a "half-pyramid" of blocks before leaping (if he wants to maximize his score) toward a flag pole. Below is a screenshot.

닌텐도의 슈퍼 마리오의 레벨 1-1 끝부분에, 마리오는 깃대의 맨 위쪽을 다다르기 위해 (그래야지 점수가 최대화할 수 있으므로), 반 쪽자리 피라미드 모양을 가진 블록을 올라갑니다. 아래는 스크린샷을 찍은 것 입니다

Super Mario Brothers

Specification (사양)

  • Write, in a file called mario.c in ~/workspace/pset1/mario/less/, a program that recreates this half-pyramid using hashes (#) for blocks.

    ~/workspace/pset1/mario/less/라는 폴더 안에 해쉬(#)를 통해 이 피라미드 반쪽을 재현하는 프로그램 mario.c를 작성하시오


  • To make things more interesting, first prompt the user for the half-pyramid’s height, a non-negative integer no greater than 23. (The height of the half-pyramid pictured above happens to be 8.)

    좀 더 흥미롭게 만들기 위해, 프로그램은 유저에게 피라미드의 높이를 받아야합니다. 높이는 23을 초과하면 안 되며, 음수가 아닌 정수여야 합니다. (위의 프로그램이 받은 높이는 8이였습니다.)


  • If the user fails to provide a non-negative integer no greater than 23, you should re-prompt for the same again.

    만약에 유저가 유효한 높이를 제공하지 못하였다면, 프로그램은 유저를 다시 물어봐야 합니다.


  • Then, generate (with the help of printf and one or more loops) the desired half-pyramid.

    유효한 높이를 받은 후, printf의 도움을 받으면서 반복문 한 개 이상을 이용해서 적합한 반쪽 피라미드를 출력해야합니다


  • Take care to align the bottom-left corner of your half-pyramid with the left-hand edge of your terminal window.

    반쪽 피라미드의 왼쪽 부분이 터미널의 왼쪽에 가지런히 정렬되도록 조십하십시오

Walkthrough

아래 비디오는 번역하지 않았으므로 자율적으로 보길 바람

Usage

Your program should behave per the example below. Assumed that the underlined text is what some user has typed.

당신의 프로그램은 아래 예시처럼 작동해야 합니다. 밑줄 친 텍스트는 유저의 입력이라고 가정하십시오.

$ ./mario
Height: 4
   ##
  ###
 ####
#####
$ ./mario
Height: 0
$ ./mario
Height: -5
Height: 4
   ##
  ###
 ####
#####
$ ./mario
Height: -5
Height: five
Height: 40
Height: 24
Height: 4
   ##
  ###
 ####
#####

Testing

Correctness (답 확인 방법)

check50 cs50/2018/x/mario/less

Style

style50 mario.c

Staff Solution (예시 프로그램)

~cs50/pset1/mario

Hints

Try to establish a relationship between (a) the height the user would like the pyramid to be, (b) what row is currently being printed, and (c) how many spaces and how many hashes are in that row. Once you establish the formula, you can translate that to C!

유저가 입력한 높이를 a라하고, 현재 몇 번째 줄이 출력되고 있는지를 b라하고, 그 출력되고 있는 줄에 출력되야하는 스페이스(여백)과 해쉬(#)가 몇 개 있어야하는 지를 cd 라 하면, 이 4개의 관계를 찾으면, 이를 C로 옮겨 적으면 됩니다!