Connection Status:
Competition Arena > HiddenMessage
SRM 316 · 2006-08-19 · by _efer_ · Simple Search, Iteration, String Parsing
Class Name: HiddenMessage
Return Type: String
Method Name: getMessage
Arg Types: (string)
Problem Statement

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.

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
0)
"compete online design event rating"
Returns: "coder"

Taking the first letter from each word yields the return "coder".

1)
"  c    o d     e      r    "
Returns: "coder"

Watch out for the leading spaces.

2)
"round  elimination during  onsite  contest"
Returns: "redoc"

"coder" written backwards.

3)
" hello  world "
Returns: "hw"
4)
"the quick brown fox jumped over the lazy dog "
Returns: "tqbfjotld"
16)
" "
Returns: ""

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

Submissions are judged against all 39 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class HiddenMessage with a public method string getMessage(string text) · 39 test cases · 2 s / 256 MB per case

Submitting as anonymous