C#

백준 2439 : 별 찍기 - 2

RIsN 2020. 12. 3. 23:47

첫째 줄에는 별 1개, 둘째 줄에는 별 2개, N번째 줄에는 별 N개를 찍는 문제

하지만, 오른쪽을 기준으로 정렬한 별(예제 참고)을 출력하시오.

첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다.
첫째 줄부터 N번째 줄까지 차례대로 별을 출력한다.

:: 성공

: 학습

: 없음

: 개선점 : 이런 식으로 공백 찍어내는 게 아니라, 진짜 오른쪽 정렬이 있을까?

using System;

namespace for01
{
    class Program
    {
        static void Main(string[] args)
        {
            // :: Input size and Parse
            int size = Int32.Parse(Console.ReadLine());

            // :: result Array
            string[] result = new string[size];

            // :: Loop with size
            for(int i = 1; i <= size; i++)
            {
                // :: Save Result
                result[i - 1] = new string(' ', size - i) + new string('*', i);
            }

            // :: Print with "Wn" for Spped
            Console.WriteLine(string.Join("\n", result));
        }
    }
}