Problem Statement
- The words in the sequence must all be within one sentence.
- The sequence must not include the first word in a sentence.
- At least two words in the sequence must begin with uppercase letters.
- The first and last words in the sequence must begin with uppercase letters.
- There may not be two adjacent words that do not begin with uppercase letters in the sequence.
- The sequence must be as long as possible. It may not be a subsequence of any longer sequence meeting the five criteria above.
For each sequence of words meeting the criteria as defined above, you should convert it to an acronym by replacing the whole sequence of words with all the uppercase letters in the words that start with uppercase letters (in order). The only caveat to this is that if there are non-letter characters at the end of the last word in the sequence, you should not replace them.
For example, "TopCoder, Inc." would become "TCI.". Note that the '.' at the end of "Inc." remains in the acronym but the ',' at the end of "TopCoder," is removed. Also, "United States of America" would be converted to "USA"; there is no 'o' because "of" does not start with an uppercase letter.
After inserting the acronyms, you should return a
Definition
- Class:
- Acronyms
- Method:
- acronize
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String acronize(String[] document)
- (be sure your method is public)
Notes
- Since new lines count as spaces, the input is identical in function to a single String that is the concatenation of all the elements of document with single spaces inserted between them.
Constraints
- document will contain between 1 and 50 elements, inclusive.
- Each element of document will contain between 1 and 50 characters, inclusive.
- Each character in document will have ASCII values between 32 and 122 inclusive.
- No element of document will have leading spaces.
- No element of document will have more than one trailing space.
- The last element of document will not have trailing spaces.
- There will not be two adjacent non-letter characters other than spaces.
- There will never be more than 2 consecutive spaces in document
Examples
{"We the people of the United States of America."}
Returns: "We the people of the USA."
"of" is not include in the acronym since it starts with a lowercase letter.
{"Don't","worry.","Be","Happy!"}
Returns: "Don't worry. BH!"
Even though there is a period, there is only one sentence according to the rules of this problem.
{"Entering contests at TopCoder, Inc.", "is a good way to develop your skills."}
Returns: "Entering contests at TCI. is a good way to develop your skills."
Be sure to include the period after "TCI" in your return.
{"Afternoon Tea"}
Returns: "Afternoon Tea"
{"Working for the Environmental Protection Agency", "is hard work."}
Returns: "Working for the EPA is hard work."
{"Working at the United States Postal Service", "in the United States of America", "is a satisfying experience."}
Returns: "Working at the USPS in the USA is a satisfying experience."
{"I would like a Bacon, Lettuce, and Tomato", "sandwich. I don't", "like Pickles, Onions, and Tomatoes."}
Returns: "I would like a BLT sandwich. I don't like POT."
{"a A & a & a B"}
Returns: "a A & a & a B"
{"The First word can't be included. In","A sequence, that is."}
Returns: "The First word can't be included. In A sequence, that is."
"The" and "In" are both the first words in sentences.
{"A Test & Test & & TEst"}
Returns: "A TT & & TEst"
Note that "&" counts as a word.
{"This is a TEST tEST Test. ", ".Go Test"}
Returns: "This is a TESTT. .Go Test"
{"This is A Hard cAse Indeed"}
Returns: "This is AHI"
{"fg"}
Returns: "fg"
{"V"}
Returns: "V"
{"djq. u E. ","absrcsal.xRirSupI."}
Returns: "djq. u E. absrcsal.xRirSupI."
{"yVvm aZOv InhHx","sXnh MHzjfbrfv k s .xks hxlYfPNf B"}
Returns: "yVvm aZOv IHMH k s .xks hxlYfPNf B"
{"ibmpdncxUopXk"}
Returns: "ibmpdncxUopXk"
{"hSMF uyxV.Q WQXPb","wP"}
Returns: "hSMF uyxV.Q WQXPb wP"
{"O y fou ","zpubbdbkp"}
Returns: "O y fou zpubbdbkp"
{"Ejc","GjIFMyI"}
Returns: "Ejc GjIFMyI"
{"PELL NM AS .XHOJAXYQZgRXRuXMR VX EZ"}
Returns: "PELL NMASVX EZ"
{"WGDC.XQCBUW"}
Returns: "WGDC.XQCBUW"
{"fX e MG LYI IMa DfOn FNJd qVEOUFFVJIV.OB Kj"}
Returns: "fX e MGLYIIMDOFNJ qVEOUFFVJIV.OB Kj"
{"f he.fh a p Ej Yf vzthcuwD"}
Returns: "f he.fh a p EY vzthcuwD"
{"vtr vwqjnpgorf ab UdGBq. n D kczf Vt","meoQf.tyxrjlP.v.ha ch vs hv oxtSxE. b yhk .v s K","Timvz"}
Returns: "vtr vwqjnpgorf ab UdGBq. n D kczf Vt meoQf.tyxrjlP.v.ha ch vs hv oxtSxE. b yhk .v s KT"
{"VCifY MVir. csg YUKM vcT Pf ql M.nY. kn I nbDY","osSRk.yDG"}
Returns: "VCifY MVir. csg YUKM vcT PMYI nbDY osSRk.yDG"
{"o.mg U NZFPVF.Knw j ErFE rOlP XaKVqEcTsW C bfUwX","Q .a br TEVIA Ban.J"}
Returns: "o.mg UNZFPVFK j EFEXKVETWCQ .a br TEVIA Ban.J"
{"HKt uQXGXAWTGWMH dNHGYpTC CrMYXLTBLw LT C ORUDUT.",".A Wt F.JUGF"}
Returns: "HKt uQXGXAWTGWMH dNHGYpTC CMYXLTBLLTCORUDUTW F.JUGF"
{"PK xnJHdmjOlKTnc Xw H OD L"}
Returns: "PK xnJHdmjOlKTnc XHOD L"
{"Vm.R iEN .v f ugM VQcojs nujGPsuaqRH kjIGby M","zSJ F utHRv P XHFfUbq phNy"}
Returns: "Vm.R iEN .v f ugM VQcojs nujGPsuaqRH kjIGby M zSJ FPXHFU phNy"
{"Y a T jwpW.UxbkJXO .D.G. gCJjRg pY CnC iGO Q","Fr.m T Y XsyBdY qDxNMEMq"}
Returns: "Y a T jwpW.UxbkJXO .D.G. gCJjRg pY CCQFTY XsyBdY qDxNMEMq"
{"S.zEovnLdg.qh i EG QLd uFLaHxVl ePP YlYb.q.o","crOeVTn.iuCLj e P c vF iPvR wjcz.wgxomhx"}
Returns: "S.zEovnLdg.qh i EGQL uFLaHxVl ePP YlYb.q.o crOeVTn.iuCLj e P c vF iPvR wjcz.wgxomhx"
{"co. uk N X.aUkxZM. MG A.QBHU pZEIJOD olZ.JbSJGY"}
Returns: "co. uk NXUZMMGAQBHU pZEIJOD olZ.JbSJGY"
{"p nlQUGIht TAAnuRa.pCKea. . XAYbL tABSwO.NbH","uf T. quBlnhYU jm . Hn pTGMRPGoC E. KK guAVFfb","Pk.Q"}
Returns: "p nlQUGIht TAAnuRa.pCKea. . XAYbL tABSwO.NbH uf T. quBlnhYU jm . HEKKPQ"
{"zgd t fvonY q wbSysrogk WoUd uiu hj ldvr H","bcyHt. z . ."}
Returns: "zgd t fvonY q wbSysrogk WoUd uiu hj ldvr H bcyHt. z . ."
{"OObj I.l.WH.Q d W zzgYHXVeJiHjX hwCT usay.mw t","f N q.m P n IX. WTPPx.kR"}
Returns: "OObj IWHQW zzgYHXVeJiHjX hwCT usay.mw t f N q.m PIX. WTPPx.kR"
{"TWG PAWN CQjbOYZ S SL SD. IGV PHRB V x.ESA.XmCX",".B BY HIII.W V a .zQ CQPIysPHYNFBBWMSK","FGUIRObUWaSYNP T"}
Returns: "TWG PAWNCQOYZSSLSDIGV PHRB V x.ESA.XmCX .B BYHIIIWV a .zQ CQPIPHYNFBBWMSKFGUIROUWSYNP T"
{"Don't", "worry.", "Be", "Happy!" }
Returns: "Don't worry. BH!"
{"A Test & Test & & TEst" }
Returns: "A TT & & TEst"