작성일 :

문제 링크

10410번 - Eligibility

설명

학생의 이름, 학부 시작일, 생년월일, 이수 과목 수가 주어질 때, ICPC 참가 자격을 판정하는 문제입니다.


접근법

먼저, 세 가지 조건을 우선순위대로 확인합니다. 학부 시작 연도가 2010년 이후이거나 출생 연도가 1991년 이후이면 eligible입니다.

다음으로, 위 조건에 해당하지 않으면서 이수 과목 수가 41개 이상이면 ineligible입니다. 그 외의 경우는 coach petitions를 출력합니다.

이후, 이름과 판정 결과를 함께 출력합니다. 날짜 문자열에서 앞 4자리만 추출하면 연도를 얻을 수 있습니다.



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;

namespace Solution {
  class Program {
    static void Main(string[] args) {
      var t = int.Parse(Console.ReadLine()!);
      for (var tc = 0; tc < t; tc++) {
        var parts = Console.ReadLine()!.Split();
        var name = parts[0];
        var start = parts[1];
        var birth = parts[2];
        var courses = int.Parse(parts[3]);

        var ys = int.Parse(start.Substring(0, 4));
        var yb = int.Parse(birth.Substring(0, 4));

        string res;
        if (ys >= 2010 || yb >= 1991) res = "eligible";
        else if (courses >= 41) res = "ineligible";
        else res = "coach petitions";

        Console.WriteLine($"{name} {res}");
      }
    }
  }
}

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

  int T; cin >> T;
  while (T--) {
    string name, start, birth; int courses;
    cin >> name >> start >> birth >> courses;

    int ys = stoi(start.substr(0, 4));
    int yb = stoi(birth.substr(0, 4));

    string res;
    if (ys >= 2010 || yb >= 1991) res = "eligible";
    else if (courses >= 41) res = "ineligible";
    else res = "coach petitions";

    cout << name << " " << res << "\n";
  }

  return 0;
}