Post

[BaekJoon] 10214번 - Baseball [Java][C++]

[BaekJoon] 10214번 - Baseball [Java][C++]

문제 링크


1. 문제 풀이


테스트 케이스 별로 9회 동안 각 팀의 점수 합을 더해서 비교만 해주면 된다.


2. 코드


1. 풀이 [Java]

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
import java.io.*;
import java.util.*;

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

        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) {
            int ysum = 0;
            int ksum = 0;

            for (int i = 0; i < 9; i++) {
                st = new StringTokenizer(br.readLine());
                int y = Integer.parseInt(st.nextToken());
                int k = Integer.parseInt(st.nextToken());
                ysum += y;
                ksum += k;
            }

            if (ysum > ksum) {
                bw.write("Yonsei\n");
            } else if (ysum < ksum) {
                bw.write("Korea\n");
            } else {
                bw.write("Draw\n");
            }
        }

        bw.flush();
    }
}


2. 풀이 [C++]

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
#include <bits/stdc++.h>
using namespace std;

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

    int t;
    cin >> t;

    while (t--) {
        int ysum = 0;
        int ksum = 0;

        for (int i = 0; i < 9; i++) {
            int y, k;
            cin >> y >> k;
            ysum += y;
            ksum += k;
        }

        if (ysum > ksum) {
            cout << "Yonsei\n";
        } else if (ysum < ksum) {
            cout << "Korea\n";
        } else {
            cout << "Draw\n";
        }
    }
}

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