समस्या
अनुवाद दिखाएँ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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।