작성일 :

문제 링크

2490번 - 윷놀이

설명

전통놀이인 윷놀이의 결과를 판단하는 문제입니다.
4개의 윷을 던져 나온 0(배)과 1(등)의 개수에 따라 결과가 결정됩니다.

결과 0의 개수
3
2
1
0
4

문제에서는 0이 몇 개 나왔는지에 따라 알파벳으로 결과를 출력해야 합니다:

  • A: 도 (0이 3개)
  • B: 개 (0이 2개)
  • C: 걸 (0이 1개)
  • D: 윷 (0이 0개)
  • E: 모 (0이 4개)

접근법

  • 총 3번 게임이 주어지며, 각 줄마다 4개의 0 또는 1이 주어집니다.
  • 각 줄에 대해 0의 개수를 세고, 이에 대응하는 알파벳을 출력합니다.

Code

[ 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
using System;

namespace Solution {
  class Program {
    static void Main(string[] args) {
      for (int i = 0; i < 3; i++) {
        var input = Console.ReadLine()!.Split();
        int cnt = 0;
        foreach (var v in input)
          if (v == "0") cnt++;

        char result = cnt switch {
          0 => 'E',
          1 => 'A',
          2 => 'B',
          3 => 'C',
          _ => 'D'
        };

        Console.WriteLine(result);
      }
    }
  }
}



[ 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
#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++) {
      bool isUpsied; cin >> isUpsied;
      if (!isUpsied) cnt++;
    }
    char ans;
    if (cnt == 0) ans = 'E';
    else if (cnt == 1) ans = 'A';
    else if (cnt == 2) ans = 'B';
    else if (cnt == 3) ans = 'C';
    else ans = 'D';
    cout << ans << "\n";
  }

  return 0;
}