작성일 :

문제 링크

14038번 - Tournament Selection

설명

토너먼트에서 6경기를 치른 결과가 주어집니다.

각 경기의 승패 결과가 주어질 때, 승리 횟수에 따라 소속 그룹을 결정하는 문제입니다.

승리가 5개 이상이면 그룹 1, 3개 이상이면 그룹 2, 1개 이상이면 그룹 3이고, 승리가 없으면 -1을 출력합니다.


접근법

6개의 경기 결과를 하나씩 읽으면서 승리 횟수를 셉니다.

예를 들어, W, L, W, W, L, W가 주어지면 승리는 4번이므로 그룹 2에 속합니다.


모든 경기 결과를 확인한 후, 승리 횟수에 따라 그룹을 결정합니다.

승리가 5개 이상이면 1, 3개 이상이면 2, 1개 이상이면 3, 없으면 -1을 출력합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;

namespace Solution {
  class Program {
    static void Main(string[] args) {
      var wins = 0;

      for (var i = 0; i < 6; i++) {
        var r = Console.ReadLine()![0];
        if (r == 'W') wins++;
      }

      if (wins >= 5) Console.WriteLine(1);
      else if (wins >= 3) Console.WriteLine(2);
      else if (wins >= 1) Console.WriteLine(3);
      else Console.WriteLine(-1);
    }
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;

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

  int wins = 0;

  for (int i = 0; i < 6; i++) {
    char r; cin >> r;
    if (r == 'W') ++wins;
  }

  if (wins >= 5) cout << 1 << "\n";
  else if (wins >= 3) cout << 2 << "\n";
  else if (wins >= 1) cout << 3 << "\n";
  else cout << -1 << "\n";

  return 0;
}