작성일 :

문제 링크

31866번 - 손가락 게임

설명

두 사람의 손가락 개수로 표식을 판정해 승패를 출력하는 문제입니다.


접근법

손가락 개수를 바위/가위/보/무효로 매핑합니다.
표식이 같으면 무승부, 한 쪽이 무효면 다른 쪽이 승리, 그 외에는 상성 규칙으로 판단합니다.


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
25
26
using System;

class Program {
  static int ToHand(int x) {
    if (x == 0) return 0;
    if (x == 2) return 1;
    if (x == 5) return 2;
    return 3;
  }

  static void Main() {
    var parts = Console.ReadLine()!.Split();
    var a = int.Parse(parts[0]);
    var b = int.Parse(parts[1]);

    var ha = ToHand(a);
    var hb = ToHand(b);

    if (ha == hb) Console.WriteLine("=");
    else if (ha == 3) Console.WriteLine("<");
    else if (hb == 3) Console.WriteLine(">");
    else if ((ha == 0 && hb == 1) || (ha == 1 && hb == 2) || (ha == 2 && hb == 0))
      Console.WriteLine(">");
    else Console.WriteLine("<");
  }
}

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

int toHand(int x) {
  if (x == 0) return 0;
  if (x == 2) return 1;
  if (x == 5) return 2;
  return 3;
}

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

  int a, b; cin >> a >> b;
  int ha = toHand(a);
  int hb = toHand(b);

  if (ha == hb) cout << "=\n";
  else if (ha == 3) cout << "<\n";
  else if (hb == 3) cout << ">\n";
  else if ((ha == 0 && hb == 1) || (ha == 1 && hb == 2) || (ha == 2 && hb == 0))
    cout << ">\n";
  else cout << "<\n";

  return 0;
}