簡単 0件解決済み 正答率0%

Gradebook Letter Counts

Turn a whole class's scores into letter grades and count how many students got each letter.

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

  • Map a score to a letter with ordered conditions
  • Tally results in a fixed-size array
  • Return counts in a defined order

問題

翻訳を表示

At the end of the term a teacher wants a quick summary of the class: how many students earned each letter grade. The scale is 90 and above for A, 80 to 89 for B, 70 to 79 for C, 60 to 69 for D and below 60 for F.

Implement grade_letter_counts(scores).

Input

scores: Every student's final score.

Output

Return five counts in the order A, B, C, D, F. An empty class gives [0, 0, 0, 0, 0].

制約

0 ≤ number of scores ≤ 10,000

0 ≤ score ≤ 100

例

例 1
入力:
scores = [95, 82, 67, 88, 45, 90]

期待される出力:
expected = [2, 2, 0, 1, 1]
入力:
std::vector<long long> scores = {95, 82, 67, 88, 45, 90};

期待される出力:
std::vector<long long> expected = {2, 2, 0, 1, 1};
入力:
long[] scores = new long[] {95, 82, 67, 88, 45, 90};

期待される出力:
long[] expected = new long[] {2, 2, 0, 1, 1};

解説

95 and 90 are A, 82 and 88 are B, 67 is D and 45 is F: [2, 2, 0, 1, 1].

例 2
入力:
scores = [79, 80, 59, 60]

期待される出力:
expected = [0, 1, 1, 1, 1]
入力:
std::vector<long long> scores = {79, 80, 59, 60};

期待される出力:
std::vector<long long> expected = {0, 1, 1, 1, 1};
入力:
long[] scores = new long[] {79, 80, 59, 60};

期待される出力:
long[] expected = new long[] {0, 1, 1, 1, 1};

解説

Each score sits on a cutoff: 79 is C, 80 is B, 59 is F and 60 is D: [0, 1, 1, 1, 1].

解き方のヒント

まずは自分で考えてから、ヒントを 1 つずつ開いてみましょう。

ヒント 1

Check the highest cutoff first so each score falls into exactly one branch.

ヒント 2

Use an array of five counters, one per letter.

ヒント 3

An empty class just returns the counters untouched.

目安の計算量

O(n) time, O(1) extra space

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

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

まだ合格した解答はありません。解いて 1 位になりましょう。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。