작성일 :

문제 링크

11367번 - Report Card Time

설명

학생 수 n과 각 학생의 이름(길이 10 미만)과 점수(0~100)가 주어지는 상황에서, 점수 구간에 따라 학점을 부여하여 이름과 학점을 출력하는 문제입니다.


접근법

점수를 학점으로 변환하는 규칙에 따라 조건문으로 판단하면 됩니다.

점수 구간별 학점 규칙은 다음과 같습니다:

  • 97~100: A+
  • 90~96: A
  • 87~89: B+
  • 80~86: B
  • 77~79: C+
  • 70~76: C
  • 67~69: D+
  • 60~66: D
  • 0~59: F


각 학생에 대해 점수를 읽고 위 규칙에 따라 학점을 결정한 후 이름과 학점을 출력합니다.

조건문을 높은 점수부터 차례로 확인하면 첫 번째로 만족하는 구간의 학점을 반환할 수 있습니다.



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
27
28
29
using System;

namespace Solution {
  class Program {
    static string Grade(int s) {
      if (s >= 97) return "A+";
      if (s >= 90) return "A";
      if (s >= 87) return "B+";
      if (s >= 80) return "B";
      if (s >= 77) return "C+";
      if (s >= 70) return "C";
      if (s >= 67) return "D+";
      if (s >= 60) return "D";
      return "F";
    }

    static void Main(string[] args) {
      var n = int.Parse(Console.ReadLine()!);

      for (var i = 0; i < n; i++) {
        var line = Console.ReadLine()!.Split();
        var name = line[0];
        var score = int.Parse(line[1]);

        Console.WriteLine($"{name} {Grade(score)}");
      }
    }
  }
}

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

string grade(int s) {
  if (s >= 97) return "A+";
  if (s >= 90) return "A";
  if (s >= 87) return "B+";
  if (s >= 80) return "B";
  if (s >= 77) return "C+";
  if (s >= 70) return "C";
  if (s >= 67) return "D+";
  if (s >= 60) return "D";
  return "F";
}

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

  int n; cin >> n;

  while (n--) {
    string name; int score; cin >> name >> score;

    cout << name << " " << grade(score) << "\n";
  }

  return 0;
}