모든 챌린지
보통 1명 해결 정답률 100.0%

Readability Grade

Estimate the school grade needed to read a text.

배우게 될 내용

  • Count letters, words and sentences
  • Apply the Coleman-Liau formula
  • Round and clamp a grade

문제

번역본 보기

The Coleman-Liau index estimates the U.S. grade level for a text: index = 0.0588 × L − 0.296 × S − 15.8, where L is the average number of letters per 100 words and S the average number of sentences per 100 words. Letters are A–Z/a–z, words are separated by spaces, and each ., ! or ? ends a sentence. Round the index to the nearest whole number.

Implement readability_grade(text).

Input

text: English text with at least one word.

Output

Return "Before Grade 1" when the index is below 1, "Grade 16+" when it is 16 or more, otherwise "Grade N".

제약 조건

1 ≤ length ≤ 10,000

예시

예시 1
입력:
text = "One fish. Two fish. Red fish. Blue fish."

예상 출력:
expected = "Before Grade 1"
입력:
std::string text = "One fish. Two fish. Red fish. Blue fish.";

예상 출력:
std::string expected = "Before Grade 1";
입력:
string text = "One fish. Two fish. Red fish. Blue fish.";

예상 출력:
string expected = "Before Grade 1";

설명

29 letters, 8 words and 4 sentences give an index below 1: "Before Grade 1".

예시 2
입력:
text = "Harry Potter was a highly unusual boy in many ways. For one thing, he hated the summer holidays more than any other time of year. For another, he really wanted to do his homework, but was forced to do it in secret, in the dead of the night. And he also happened to be a wizard."

예상 출력:
expected = "Grade 5"
입력:
std::string text = "Harry Potter was a highly unusual boy in many ways. For one thing, he hated the summer holidays more than any other time of year. For another, he really wanted to do his homework, but was forced to do it in secret, in the dead of the night. And he also happened to be a wizard.";

예상 출력:
std::string expected = "Grade 5";
입력:
string text = "Harry Potter was a highly unusual boy in many ways. For one thing, he hated the summer holidays more than any other time of year. For another, he really wanted to do his homework, but was forced to do it in secret, in the dead of the night. And he also happened to be a wizard.";

예상 출력:
string expected = "Grade 5";

설명

The average word and sentence lengths give an index that rounds to 5: "Grade 5".

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Count letters, words, and sentences separately from the same text.

힌트 2

Use the given index formula with letters per 100 words and sentences per 100 words.

힌트 3

Round to the nearest whole number before choosing the output label.

예상 복잡도

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

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

# 코더 언어 시간 메모리 AI 평가 풀이
1 ННикита Python 1,033 ms - 5/5 코드 보기

다른 사람의 풀이 보기

커뮤니티 풀이

스포일러: 아래에 전체 풀이 1개가 있습니다 먼저 직접 풀어보세요. 다른 개발자의 코드와 AI 리뷰도 참고할 수 있습니다. 로그인하고 문제를 풀면 토론에 참여할 수 있습니다.