問題
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つずつ開いてみましょう。
ヒント 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用に調整されています。上記の説明と制約に従ってください。