본문 바로가기

Algorithm

(C++) - 백준(BOJ) 10996번 : 별찍기 - 21 답

반응형

https://www.acmicpc.net/problem/10996


출력 : n*2만큼 

짝수번째 줄 n만큼 *출력

홀수번째 줄 n-1만큼 출력

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
if (n == 1) { cout << "*" << '\n'return 0; }
    for (int i = 1; i <= n*2; i++)
    {
        if (i % == 1)
        {
            if (n % == 0)
            {
                for (int j = 1; j <= n / 2; j++)
                    cout << "* ";
                cout << '\n';
            }
            else
            {
                for (int j = 1; j <= (n + 1/ 2; j++)
                    cout << "* ";
                cout << '\n';
            }
        }
        else//짝수 번째 줄
        {
            if (n % == 0)
            {
                for (int j = 1; j <= n / 2; j++)
                    cout << " *";
                cout << '\n';
            }
            else
            {
                for (int j = 1; j <= (n - 1/ ; j++)
                    cout << " *";
                cout << '\n';
            }
        }
    }
}
cs