#C66. Longest Word Finder
Longest Word Finder
Longest Word Finder
Given a string containing words separated by commas, your task is to find the longest word among them. If there are multiple words with the same maximum length, return the first occurrence.
In mathematical terms, let \(w_1, w_2, \dots, w_n\) be the words such that the input string is \(w_1,w_2,\dots,w_n\). You need to find \(w_k\) such that \(\lvert w_k \rvert \geq \lvert w_i \rvert\) for all \(i\) and if there are multiple values, choose the one with the smallest index \(k\).
inputFormat
The input is provided through standard input (stdin) as a single non-empty line. This line consists of words separated by commas. For example: cat,dog,elephant,lion
.
outputFormat
Output the longest word to standard output (stdout). If multiple words have the maximum length, output the first one encountered in the input.
## samplecat,dog,elephant,lion
elephant