Statistics

Problem Statement for "HiddenMessage"

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. " hello world "

    Returns: "hw"

  5. "the quick brown fox jumped over the lazy dog "

    Returns: "tqbfjotld"

  6. " this is the easy problem "

    Returns: "titep"

  7. " "

    Returns: ""

  8. " a "

    Returns: "a"

  9. "a a a a a a a a a a a a a a a a a a a a a a a a a"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaa"

  10. "a a a a a a a a a a a a a a a a a a a a a a a a a "

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaa"

  11. "this solution passes"

    Returns: "tsp"

  12. " aaaaaaaaaa aaaaaaaaaaaaa a"

    Returns: "aaa"

  13. " return the hidden message "

    Returns: "rthm"

  14. "interesting exercise for learning how to program"

    Returns: "ieflhtp"

  15. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

    Returns: "x"

  16. "y"

    Returns: "y"

  17. " "

    Returns: ""

    Since there are no words here, the empty string must be returned.

  18. " c plus plus java c sharp basic "

    Returns: "cppjcsb"

  19. " dice gambling las vegas"

    Returns: "dglv"

  20. " soccer basketball volleyball "

    Returns: "sbv"

  21. " id wht omanly heay atuss n macon "

    Returns: "iwohanm"

  22. "fun fun fun fun fun fun fun fun fun fun fun fun"

    Returns: "ffffffffffff"

  23. " generating random text "

    Returns: "grt"

  24. " sdss dsdd sdddsssddsd dssds sdddsdsds"

    Returns: "sdsds"

  25. "fjd vasdkop asbdu ksaldhr alsk fhfjkas lsdkre o"

    Returns: "fvakaflo"

  26. " sdfauier sduioio ertwmn looopa fds"

    Returns: "sself"

  27. " agree tonight sounds pain "

    Returns: "atsp"

  28. " nobody change now"

    Returns: "ncn"

  29. "no on no on no on no"

    Returns: "nononon"

  30. "this is the last test case"

    Returns: "titltc"

  31. " "

    Returns: ""

  32. " dd"

    Returns: "d"

  33. "c r"

    Returns: "cr"

  34. " c o d e r "

    Returns: "coder"

  35. " c"

    Returns: "c"

  36. "aaa bbb"

    Returns: "ab"

  37. "z"

    Returns: "z"

  38. " "

    Returns: ""

  39. "aaaaaaa d"

    Returns: "ad"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: