TopcoderArchiveVisit Topcoder
SRM19 Aug 2006
SRM 316

HiddenMessage

Problem statement, definition, constraints, and public examples.

Problem Statement

Some texts contain hidden messages. In the context of this problem, the hidden message of a text is composed of the first letter from each word in the text, in the order they appear.

Given a String text, consisting of only lowercase letters and spaces, return the hidden message. A word is a maximal sequence of consecutive letters. There may be multiple spaces between words. Also, text may contain only spaces.

Definition

Class:
HiddenMessage
Method:
getMessage
Parameters:
String
Returns:
String
Method signature:
String getMessage(String text)
(be sure your method is public)

Constraints

  • text will contain between 1 and 50 characters, inclusive.
  • Each character of text will be either a lowercase letter ('a'-'z'), or a space (' ').

Examples

  1. "compete online design event rating"
    Returns: "coder"
    Taking the first letter from each word yields the return "coder".
  2. "  c    o d     e      r    "
    Returns: "coder"
    Watch out for the leading spaces.
  3. "round  elimination during  onsite  contest"
    Returns: "redoc"
    "coder" written backwards.
  4. " "
    Returns: ""
    Since there are no words here, the empty string must be returned.
Back to all problems