Statistics

Problem Statement for "Initials"

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

Definition

Class:
Initials
Method:
getInitials
Parameters:
String
Returns:
String
Method signature:
String getInitials(String name)
(be sure your method is public)

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

  1. "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.

  2. "single"

    Returns: "s"

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

  3. "looks good to me"

    Returns: "lgtm"

  4. "single round match"

    Returns: "srm"

  5. "a aa aaa aa a bbb bb b bb bbb"

    Returns: "aaaaabbbbb"

  6. "a aa a"

    Returns: "aaa"

  7. "a b c dddddd e"

    Returns: "abcde"

  8. "flskdj sadjsalkjdklas daskljdlaksjdlsa daskldjas"

    Returns: "fsdd"

  9. "akncagfm kaigf r aibbk"

    Returns: "akra"

  10. "aa p bc a dh kgcgbmkabhdg j i cubbawbg"

    Returns: "apbadkjic"

  11. "ecbk cqabfk l hmbfgacf"

    Returns: "eclh"

  12. "h caihalbamfv g enaha i baf g wbeehaa nh"

    Returns: "hcgeibgwn"

  13. "qudabel m da mbbej d f a ddg"

    Returns: "qmdmdfad"

  14. "sr li n b q"

    Returns: "slnbq"

  15. "aeal bicdebeaa a niblg c be cqf a"

    Returns: "abancbca"

  16. "hp c ed badb kqew"

    Returns: "hcebk"

  17. "a khj ngab cg mfm"

    Returns: "akncm"

  18. "y uhu"

    Returns: "yu"

  19. "e bdr io a ncbuiafbbebfrmddm kbceifg"

    Returns: "ebiank"

  20. "dda gibkeaaar lc facafigeiol u cbcfaqnfa eanibp"

    Returns: "dglfuce"

  21. "e gjfkohsie a i bn e rbegheb puheibbbbibd yhffcr"

    Returns: "egaiberpy"

  22. "cjkp a ad ba akb"

    Returns: "caaba"

  23. "m e b eeb q f g iem"

    Returns: "mebeqfgi"

  24. "a ar dabgn isa kae c bdwm cd aa"

    Returns: "aadikcbca"

  25. "ag wakk a aqesea aahjebd"

    Returns: "awaaa"

  26. "j bbd ljokem gk epa qa bko cqad"

    Returns: "jblgeqbc"

  27. "ebgae t mj a ibeog bfgw bba"

    Returns: "etmaibb"

  28. "l bd kcs l cc agcfe ddfcrfcej cg bb c"

    Returns: "lbklcadcbc"

  29. "aa f daekrd ggimqf c gaclj rdeflbecc"

    Returns: "afdgcgr"

  30. "eo mc s b"

    Returns: "emsb"

  31. "a djkfdc a c c r bbhaj be"

    Returns: "adaccrbb"

  32. "ce gfadkfkbxad hfg eae df vpcjafeaid q"

    Returns: "cghedvq"

  33. "a gecbbedhcracdbb ce hgghab cnaa af aada qas"

    Returns: "agchcaaq"

  34. "lbfastrmkap gk j oais pjdua o bcc dbjq"

    Returns: "lgjopobd"

  35. "al upfhcaacchkdedjhdddnqa bsei ch qje dt cb"

    Returns: "aubcqdc"

  36. "m enho k aaka ckf c k op"

    Returns: "mekaccko"

  37. "hkje a lg is c migjc aa"

    Returns: "halicma"

  38. "bhnaa kgbbgnmg bauaab b ad ghsfbbbaw b ajf ifcalgb"

    Returns: "bkbbagbai"

  39. "c a bd"

    Returns: "cab"

  40. "g d"

    Returns: "gd"

  41. "e afadbnph f anraebnejl sabbbaaan ekdcgda al"

    Returns: "eafasea"

  42. "raa hiafah jmfjjeap cm l bjbf calr"

    Returns: "rhjclbc"

  43. "jc ddc aoa edgpadhnx r ap kj rh"

    Returns: "jdaerakr"

  44. "erbciope efb agcd ha be a"

    Returns: "eeahba"

  45. "a cno e dhbcf d faqdrdd"

    Returns: "aceddf"

  46. "bmj hb dembbbn cbee"

    Returns: "bhdc"

  47. "udlelbme g adpala h abh e f ka"

    Returns: "ugahaefk"

  48. "k he m"

    Returns: "khm"

  49. "fb jng h cjb b ja h"

    Returns: "fjhcbjh"

  50. "bdccde ah d cp az djb a d"

    Returns: "badcadad"

  51. "o diagiyaei hga c hdng f batobrjl"

    Returns: "odhchfb"

  52. "d dgbbh ofo da l"

    Returns: "ddodl"

  53. "iifc hmi ce"

    Returns: "ihc"

  54. "jh d heet kd jccbibcqma bebg fegebdcagf ajvdaamba"

    Returns: "jdhkjbfa"

  55. "kq"

    Returns: "k"

  56. "lh bff chdchrjj bdoh a l"

    Returns: "lbcbal"

  57. "adbcag ddbiaalbbbc fcwai c hajainie haefo m tdm l"

    Returns: "adfchhmtl"

  58. "nvsc abgc bgvuaqacj goovh ckfb"

    Returns: "nabgc"

  59. "dckglb a qhjkjdb bax"

    Returns: "daqb"

  60. "bd ab h a"

    Returns: "baha"

  61. "bs f a n w"

    Returns: "bfanw"

  62. "d b eb a m c"

    Returns: "dbeamc"

  63. "g cc eb"

    Returns: "gce"

  64. "d fg f kbc a"

    Returns: "dffka"

  65. "b mk l bu c"

    Returns: "bmlbc"

  66. "db l hl"

    Returns: "dlh"

  67. "es b d cch"

    Returns: "ebdc"

  68. "g et qqb b"

    Returns: "geqb"

  69. "a b c d e f g"

    Returns: "abcdefg"

  70. "j ohn fitzge rald ken nedy"

    Returns: "jofrkn"

  71. "a a aa a aa a a"

    Returns: "aaaaaaa"

  72. "a a a a"

    Returns: "aaaa"

  73. "he is a dog"

    Returns: "hiad"

  74. "meep blubiscus kortanem srmrl asdfsd kla dsa etd"

    Returns: "mbksakde"


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: