問題
翻訳を表示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.
制約
0 ≤ length ≤ 10,000
例
例 1
入力:
text = "I love programming"
期待される出力:
expected = "programming"
入力:
std::string text = "I love programming";
期待される出力:
std::string expected = "programming";
入力:
string text = "I love programming";
期待される出力:
string expected = "programming";
解説
"programming" has 11 letters, more than the others.
例 2
入力:
text = "cat dog cow"
期待される出力:
expected = "cat"
入力:
std::string text = "cat dog cow";
期待される出力:
std::string expected = "cat";
入力:
string text = "cat dog cow";
期待される出力:
string expected = "cat";
解説
All are 3 letters; the first, "cat", wins.
参考資料
この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。