Post

[BaekJoon] #5522 - 카드 게임 [Java][C++][Python]

[BaekJoon] #5522 - 카드 게임 [Java][C++][Python]

문제 링크


1. 아이디어

다섯 게임의 점수를 모두 더한 총점을 출력하며, 점수가 한 줄에 하나씩 주어지므로 줄 단위로 다섯 번 읽는다.


2. 코드

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

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

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

        int sum = 0;
        for (int i = 0; i < 5; i++) {
            sum += Integer.parseInt(br.readLine());
        }

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

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

    int sum = 0;
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        sum += x;
    }

    cout << sum;
}
1
2
3
4
5
6
7
8
9
import sys

input = sys.stdin.readline

total = 0
for _ in range(5):
    total += int(input())

print(total)

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