簡単 6件解決済み 正答率75.0%

Letter Grade

Turn a test score into a letter grade.

このチャレンジで学べること

  • Map score ranges to grades
  • Order conditions from highest to lowest
  • Handle boundary values exactly

問題

翻訳を表示

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

例

例 1
入力:
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.

例 2
入力:
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用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

# コーダー 言語 時間 メモリ AI 評価 解答
1 HJhettory Jurash Python 942 ms - 5/5 コードを見る
2 RCRiccardo Corti Python 978 ms - 4/5 コードを見る
3 LMLaura Mahlow Python 983 ms - 5/5 コードを見る
4 ДЗДавид Зайдулин Python 1,018 ms - 4/5 コードを見る
5 PKPornchai Kaewkrabil Go 1,433 ms - 4/5 コードを見る
6 GTGarlic The Destroyer Rust 1,563 ms - 5/5 コードを見る

他の人の解答から学ぶ

コミュニティの解答

ネタバレ注意: この下に解答が6件あります まずは自分で挑戦してみましょう。他の開発者のコードやAIレビューも見ることができます。 サインインして課題を解くと議論に参加できます。