Longest Word
InterviewTime limit1sMemory limit128 MB
Scan text until the token E-N-D, split it into words made of letters and hyphens, and print the longest such word in lowercase, breaking ties by first occurrence.
- Level
Easy3 of 10
- Topics
- String, Implementation, Simulation
- Solved
- No attempts yet
Problem
A word consists only of letters (a-z, A-Z) and hyphens (-). Given a text made up of words mixed with other characters (periods, digits, symbols, and so on), write a program that finds the longest word.
For example, Apple has length 5, son-in-law has length 10, and ACM-ICPC has length 8.
Input
The input consists of several lines of text and is at most 10,000 characters long. No single word is longer than 100 characters. The token E-N-D marks the end of the input, so E-N-D and everything after it is ignored, and E-N-D itself is not counted as a word.
Output
Print the longest word in lowercase. If several words share the greatest length, print the one that appears first in the text.