Post

[BaekJoon] #25314 - 코딩은 체육과목 입니다 [Java][C++][Python]

[BaekJoon] #25314 - 코딩은 체육과목 입니다 [Java][C++][Python]

문제 링크


1. 아이디어

$N$바이트까지 저장할 수 있는 정수 자료형의 이름을 구하는 문제로, long int가 4바이트이고 long이 하나 더 붙을 때마다 4바이트씩 늘어난다. $N$은 4의 배수로 주어지므로 long을 $N / 4$번 쓰고 마지막에 int를 붙인다.


2. 코드

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 = 0; i < n / 4; i++) {
            sb.append("long ");
        }
        sb.append("int");

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

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

    int n;
    cin >> n;

    for (int i = 0; i < n / 4; i++) {
        cout << "long ";
    }
    cout << "int";
}
1
2
3
4
5
6
import sys

input = sys.stdin.readline

n = int(input())
print("long " * (n // 4) + "int")

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