문제
Convert a score from 0 to 100 into a letter grade: 90 and above is A, 80–89 is B, 70–79 is C, 60–69 is D, and below 60 is F.
Implement letter_grade(score).
Input
score: The test score.
Output
Return the letter as a one-character string.
제약 조건
0 ≤ score ≤ 100
예시
입력:
score = 85
예상 출력:
expected = "B"
입력:
long long score = 85;
예상 출력:
std::string expected = "B";
입력:
long score = 85;
예상 출력:
string expected = "B";
설명
85 is at least 80 but below 90, so the grade is B.
입력:
score = 59
예상 출력:
expected = "F"
입력:
long long score = 59;
예상 출력:
std::string expected = "F";
입력:
long score = 59;
예상 출력:
string expected = "F";
설명
59 is below 60, so the grade is F.
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
Compare the score against the highest passing threshold first and work downward.
힌트 2
A chain of ordered comparisons is the simplest way to map ranges to letters.
힌트 3
Make sure boundary scores like 90, 80, 70, and 60 fall into the higher grade band.
예상 복잡도
O(1) time, O(1) extra space
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.