Post

[BaekJoon] 2490번 - 윷놀이 [Java][C++]

[BaekJoon] 2490번 - 윷놀이 [Java][C++]

문제 링크


1. 문제 풀이


등(1) 의 개수를 통해 어떤 윷짝인지 조건문으로 판별하면 된다.


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
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));
        StringTokenizer st;

        for (int i = 0; i < 3; i++) {
            int cnt = 0;
            st = new StringTokenizer(br.readLine());
            while (st.hasMoreTokens()) {
                cnt += Integer.parseInt(st.nextToken());
            }

            if (cnt == 0) {
                System.out.println("D");
            } else if (cnt == 1) {
                System.out.println("C");
            } else if (cnt == 2) {
                System.out.println("B");
            } else if (cnt == 3) {
                System.out.println("A");
            } else {
                System.out.println("E");
            }
        }
    }
}


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

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

    for (int i = 0; i < 3; i++) {
        int cnt = 0;
        for (int j = 0; j < 4; j++) {
            int x;
            cin >> x;
            cnt += x;
        }

        if (cnt == 0) {
            cout << 'D' << '\n';
        } else if (cnt == 1) {
            cout << 'C' << '\n';
        } else if (cnt == 2) {
            cout << 'B' << '\n';
        } else if (cnt == 3) {
            cout << 'A' << '\n';
        } else {
            cout << 'E' << '\n';
        }
    }
}

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