Longest Word

Interview

Time limit1sMemory limit128 MB

Summary
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.

Examples3

  1. Example 1

    Input
      ACM International Collegiate Programming Contest (abbreviated as 
    ACM-ICPC or just ICPC) is an annual multi-tiered computer programming 
    competition among the universities of the world. The contest is 
    sponsored by IBM. Headquartered at Baylor University, with autonomous 
    regions on six continents, the ICPC is directed by Baylor Professor 
    William B. Poucher, Executive Director, and operates under the 
    auspices of the Association for Computing Machinery (ACM). 
    
      The 2012 ACM-ICPC Asia Hatyai Regional Programming Contest is 
    held during 15-16 November 2012. It is hosted by Prince of Songkla 
    University, Hatyai campus. E-N-D
    
    Expected output
    international
    
  2. Example 2

    Input
    cat son-in-law dog E-N-D
    
    Expected output
    son-in-law
    
  3. Example 3

    Input
    the quick brown fox E-N-D
    
    Expected output
    quick