Einfach 0 gelöst 0% Erfolgsquote

Longest Word

Find the longest word in a sentence.

Return the longest word in text (words are separated by spaces). If several words share the longest length, return the first one.

Implement longest_word(text).

Input

text: The sentence.

Output

Return the longest word, or an empty string if there are no words.

Einschränkungen

0 ≤ length ≤ 10,000

Beispiele

Beispiel 1
Eingabe:
text = "I love programming"

Erwartete Ausgabe:
expected = "programming"
Eingabe:
std::string text = "I love programming";

Erwartete Ausgabe:
std::string expected = "programming";
Eingabe:
string text = "I love programming";

Erwartete Ausgabe:
string expected = "programming";

Erläuterung

"programming" has 11 letters, more than the others.

Beispiel 2
Eingabe:
text = "cat dog cow"

Erwartete Ausgabe:
expected = "cat"
Eingabe:
std::string text = "cat dog cow";

Erwartete Ausgabe:
std::string expected = "cat";
Eingabe:
string text = "cat dog cow";

Erwartete Ausgabe:
string expected = "cat";

Erläuterung

All are 3 letters; the first, "cat", wins.

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.