HOIT_B

[백준]C# 2445 별찍기8 본문

작고소중한 알고리즘 풀기

[백준]C# 2445 별찍기8

HOIT_77 2021. 1. 24. 14:02
728x90

[문제]

www.acmicpc.net/problem/2445

 

2445번: 별 찍기 - 8

첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.

www.acmicpc.net

[ ]

별과 별 사이에 공백이 N*2-2*i 이다. 

문제의 예시를 보면

* -8-*

** -6- ** 

.

.

*****-0-***** 

 

[코드]

using System;

class star{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        
        for(int i=1; i<=n; i++){
            
            for(int j=1; j<=i; j++){
                Console.Write("*");
            }
            for(int k=1; k<=(2*n)-(2*i); k++){
                Console.Write(" ");
            }
            for(int j=1; j<=i; j++){
                Console.Write("*");
            }
            Console.WriteLine();
        }
        //아래
        for(int i=1; i<n; i++){
            for(int j=1; j<=n-i; j++){
                Console.Write("*");
            }
            for(int k=1; k<=2*i; k++){
                Console.Write(" ");
            }
            for(int j=1; j<=n-i; j++){
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}

 

728x90

'작고소중한 알고리즘 풀기' 카테고리의 다른 글

[백준]C# 2446 별찍기7  (0) 2021.01.25
[백준] C# 2522 별찍기 12  (0) 2021.01.24
[백준]C# 2442 별 찍기 5  (0) 2021.01.23
[백준] 1924 번 C#  (0) 2021.01.23
[백준] 11022번 C#  (0) 2021.01.23
Comments