#K5986. Longest Word Finder

    ID: 30958 Type: Default 1000ms 256MiB

Longest Word Finder

Longest Word Finder

Given a string, your task is to find the longest contiguous sequence of alphabetic characters (both uppercase and lowercase letters are allowed). The word is defined as a maximal substring composed only of letters from A to Z or a to z. If there are multiple words that have the same maximum length, return the one that appears first in the string.

You can assume that the input will contain at least one letter.

Examples:

  • Input: "The quick brown fox jumped over the lazy dog" → Output: "jumped"
  • Input: "A journey of a thousand miles begins with a single step" → Output: "thousand"
  • Input: "May the force be with you" → Output: "force"

The solution may employ regular expressions or manual parsing. The formula for determining the length of any word is given by \(length(word)\), and the selected word should satisfy:

[ word = \underset{w \in Words}{\operatorname{argmax}}; length(w)\n]

inputFormat

The input consists of a single line containing the string to be analyzed. The string may include spaces, punctuation, and numerical digits.

outputFormat

Output the longest word (i.e., the longest contiguous sequence of alphabetic characters) found in the input string. If there are multiple candidates, output the one that appears first in the string.

## sample
The quick brown fox jumped over the lazy dog
jumped