모든 챌린지
쉬움 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

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위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.