Connection Status:
Competition Arena > Initials
SRM 698 (Google) · 2016-08-27 · by cgy4ever · String Parsing
Class Name: Initials
Return Type: String
Method Name: getInitials
Arg Types: (string)
Problem Statement

Problem Statement

When dealing with long names and phrases, we sometimes use the initial letters of words to form its acronym. For example, we use "JFK" instead of "John Fitzgerald Kennedy", "lgtm" instead of "looks good to me", and so on.

You are given a String name. This String contains a phrase: one or more words separated by single spaces. Please compute and return the acronym of this phrase. (As above, the acronym should consist of the first letter of each word, in order.)

Constraints

  • name will contain between 1 and 50 characters, inclusive.
  • Each character in s will be a space or a lowercase English letter ('a' - 'z').
  • The first and last character in s will not be a space.
  • No two continuous spaces can appear in s.
Examples
0)
"john fitzgerald kennedy"
Returns: "jfk"

There are three words: "john", "fitzgerald" and "kennedy". Their first letters are 'j', 'f' and 'k'. The correct return value is their concatenation: the string "jfk". Note that all letters in our problem are in lowercase.

1)
"single"
Returns: "s"

There is only one word: "single". Its acronym has a single letter.

2)
"looks good to me"
Returns: "lgtm"
3)
"single round match"
Returns: "srm"
4)
"a aa aaa aa a bbb bb b bb bbb"
Returns: "aaaaabbbbb"

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

Coding Area

Language: C++17 · define a public class Initials with a public method string getInitials(string name) · 74 test cases · 2 s / 256 MB per case

Submitting as anonymous