Tutte le sfide
Facile 0 risolte 0% di accettazione

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.

Vincoli

0 ≤ length ≤ 10,000

Esempi

Esempio 1
Input:
text = "I love programming"

Output atteso:
expected = "programming"
Input:
std::string text = "I love programming";

Output atteso:
std::string expected = "programming";
Input:
string text = "I love programming";

Output atteso:
string expected = "programming";

Spiegazione

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

Esempio 2
Input:
text = "cat dog cow"

Output atteso:
expected = "cat"
Input:
std::string text = "cat dog cow";

Output atteso:
std::string expected = "cat";
Input:
string text = "cat dog cow";

Output atteso:
string expected = "cat";

Spiegazione

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

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.