#C79. Longest Word Finder
Longest Word Finder
Longest Word Finder
You are given a sentence consisting of one or more words separated by whitespace. Your task is to find and output the longest word in the sentence. If there are several words with the same maximum length, output the one that appears first in the sentence.
Note: Words are defined as sequences of non-space characters. For example, in the sentence 'The quick brown fox', the longest word is 'quick'.
Mathematical Formulation:
Let \( S = \{w_1, w_2, \dots, w_n\} \) be the words in the input sentence. Find \( w_k \) such that \( |w_k| = \max_{1 \leq i \leq n} |w_i| \) and if there exists \( i \lt k \) with \( |w_i| = |w_k| \), choose the smallest such \( k \).
inputFormat
A single line containing the sentence. The sentence may include multiple words separated by spaces.
outputFormat
Output the longest word in the sentence. If there are multiple words of maximum length, output the first one.## sample
programming
programming