Problema
Ver traducciónReturn 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.
Restricciones
0 ≤ length ≤ 10,000
Ejemplos
Ejemplo 1
Entrada:
text = "I love programming"
Salida esperada:
expected = "programming"
Entrada:
std::string text = "I love programming";
Salida esperada:
std::string expected = "programming";
Entrada:
string text = "I love programming";
Salida esperada:
string expected = "programming";
Explicación
"programming" has 11 letters, more than the others.
Ejemplo 2
Entrada:
text = "cat dog cow"
Salida esperada:
expected = "cat"
Entrada:
std::string text = "cat dog cow";
Salida esperada:
std::string expected = "cat";
Entrada:
string text = "cat dog cow";
Salida esperada:
string expected = "cat";
Explicación
All are 3 letters; the first, "cat", wins.
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.