Problem
Übersetzung anzeigenA word is a run of non-space characters. Count the words in text; there may be extra spaces at the start, end or between words.
Implement count_words(text).
Input
text: The text to count.
Output
Return the number of words.
Einschränkungen
0 ≤ length ≤ 10,000
Beispiele
Beispiel 1
Eingabe:
text = "Learn to code today"
Erwartete Ausgabe:
expected = 4
Eingabe:
std::string text = "Learn to code today";
Erwartete Ausgabe:
long long expected = 4;
Eingabe:
string text = "Learn to code today";
Erwartete Ausgabe:
long expected = 4;
Erläuterung
Four words separated by spaces: 4.
Beispiel 2
Eingabe:
text = " "
Erwartete Ausgabe:
expected = 0
Eingabe:
std::string text = " ";
Erwartete Ausgabe:
long long expected = 0;
Eingabe:
string text = " ";
Erwartete Ausgabe:
long expected = 0;
Erläuterung
Only spaces, so there are no words: 0.
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.