본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 11367 : Report Card Time

반응형

https://www.acmicpc.net/problem/11367

 

11367번: Report Card Time

The input will begin with a single line containing just a whole number, n, of the number of hobbits in the class, followed by n lines in the form a b, where a is the hobbit’s name (only alphabetical characters) and b is the hobbit’s grade, given as a w

www.acmicpc.net

if문 써보는 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

이름, test case 수, 점수에 대한 변수 선언 후 입력받습니다.

📔 풀이과정

기준에 따른 학점을 반환하는 함수 getGrade를 수행합니다.

📔 정답출력

형식에 맞춥니다.


📕 Code

📔 C++

#include <bits/stdc++.h>
using namespace std;
string name;
int t, score;

string getGrade(int score){
  if(score >= 97) return "A+";
  if(90 <= score && score <= 96) return "A";
  if(87 <= score && score <= 89) return "B+";
  if(80 <= score && score <= 86) return "B";
  if(77 <= score && score <= 79) return "C+";
  if(70 <= score && score <= 76) return "C";
  if(67 <= score && score <= 69) return "D+";
  if(60 <= score && score <= 66) return "D";
  return "F";
}

int main(){
  cin >> t;
  while(t--){
    cin >> name >> score;
    cout << name << ' ' << getGrade(score) << '\n';
  }
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.