All problems

Problem 219

Longest Word in a Sentence

Easy · 10 pts · String

Problem

You are given a sentence of lowercase words separated by single spaces. Print its longest word. If several words share the maximum length, print the one that comes first in the sentence. Split the sentence into words and scan them once, replacing the current best only when a word is strictly longer. Using strictly longer is what keeps the first word in case of a tie.

Input

A single line of words of lowercase letters separated by single spaces.

Output

Print the longest word.

Constraints

1 <= length <= 100000

Example input

the quick brown fox

Example output

quick

Explanation

In "the quick brown fox", quick and brown both have 5 letters, more than the other words. quick comes first, so it is the answer.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Check String Rotation Next: Substrings with K Distinct Characters