ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

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.

เงื่อนไข

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 กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก