Post

[BaekJoon] #2556 - 별 찍기 - 14 [Java][C++][Python]

[BaekJoon] #2556 - 별 찍기 - 14 [Java][C++][Python]

문제 링크


1. 아이디어

지문이 별을 찍을 모양을 정하지 않으므로, 별 $N$개로 이루어진 줄을 $N$줄 찍는 정사각형으로 채운다.


2. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        int n = Integer.parseInt(br.readLine());

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                sb.append("*");
            }
            sb.append("\n");
        }

        System.out.println(sb);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cout << '*';
        }
        cout << '\n';
    }
}
1
2
3
4
5
6
7
8
9
10
11
import sys

input = sys.stdin.readline

n = int(input())

out = []
for _ in range(n):
    out.append("*" * n)

print("\n".join(out))

This post is licensed under CC BY 4.0 by the author.