#K35022. Longest Word Finder

    ID: 25439 Type: Default 1000ms 256MiB

Longest Word Finder

Longest Word Finder

You are given a list of words, and your task is to determine the longest word in the list. In the case where multiple words share the maximum length, you should return the one that appears first in the list.

The problem involves reading input from stdin and sending the output to stdout. Make sure to adhere to this I/O format as it will be used for automated evaluation.

Note: If there is a tie (i.e., two or more words have the same maximum length), the word that appears first in the input order should be returned.

Mathematical Representation: Let \( W = \{w_1, w_2, \dots, w_n\} \) be the set of input words, and define \( L(w) \) as the length of word \( w \). The answer is the word \( w_k \) such that \( L(w_k) = \max_{1 \leq i \leq n} L(w_i) \) and for any \( j < k \) with \( L(w_j) = L(w_k) \), \( w_j \) is chosen.

inputFormat

The input is read from stdin and consists of:

  • The first line contains an integer \( n \) representing the number of words.
  • The following \( n \) lines each contain a single word.

All words are non-empty and contain only alphabetical characters.

outputFormat

Output to stdout a single line containing the longest word from the list. If there is a tie for the longest word, output the one that appears first in the input order.

## sample
4
hello
world
supercalifragilisticexpialidocious
hi
supercalifragilisticexpialidocious