Problem
Original anzeigen (Englisch)Der Coleman-Liau-Index schätzt die US-Schulstufe für einen Text: index = 0.0588 × L − 0.296 × S − 15.8, wobei L die durchschnittliche Buchstabenzahl pro 100 Wörter und S die durchschnittliche Satzanzahl pro 100 Wörter ist. Buchstaben sind A–Z/a–z, Wörter werden durch Leerzeichen getrennt, und jedes ., ! oder ? beendet einen Satz. Runde den Index auf die nächste ganze Zahl.
Implementiere readability_grade(text).
Eingabe
text: Englischer Text mit mindestens einem Wort.
Ausgabe
Gib "Before Grade 1" zurück, wenn der Index unter 1 liegt, "Grade 16+", wenn er 16 oder mehr beträgt, sonst "Grade N".
Einschränkungen
1 ≤ Länge ≤ 10.000
Beispiele
Eingabe:
text = "One fish. Two fish. Red fish. Blue fish."
Erwartete Ausgabe:
expected = "Before Grade 1"
Eingabe:
std::string text = "One fish. Two fish. Red fish. Blue fish.";
Erwartete Ausgabe:
std::string expected = "Before Grade 1";
Eingabe:
string text = "One fish. Two fish. Red fish. Blue fish.";
Erwartete Ausgabe:
string expected = "Before Grade 1";
Erläuterung
29 Buchstaben, 8 Wörter und 4 Sätze ergeben einen Index unter 1: "Before Grade 1".
Eingabe:
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."
Erwartete Ausgabe:
expected = "Grade 5"
Eingabe:
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.";
Erwartete Ausgabe:
std::string expected = "Grade 5";
Eingabe:
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.";
Erwartete Ausgabe:
string expected = "Grade 5";
Erläuterung
Die durchschnittliche Wort- und Satzlänge ergibt einen Index, der auf 5 gerundet wird: "Grade 5".
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.