Statistics

Problem Statement for "bloggoShortcuts"

Problem Statement

You are helping to develop a weblog-management system called bloggo. Although bloggo pushes all content to the front end of a website in HTML, not all content authors enjoy using HTML tags in their text. To make their lives easier, bloggo offers a simple syntax called shortcuts to achieve some HTML textual effects. Your job is to take a document written with shortcuts and translate it into proper HTML.

One shortcut is used to make italicized text. HTML does this with the <i> and </i> tags, but in bloggo, an author can simply enclose a piece of text using two instances of the underscore character, '_'. Thus, where a content author writes


  You _should_ see the baby elephant at the zoo!

bloggo will publish the following instead.


  You <i>should</i> see the baby elephant at the zoo!

Another shortcut serves to render text in boldface, which HTML accomplishes with <b> and </b> tags. Bloggo lets content authors do the same with paired instances of the asterisk character, '*'. When a content author writes the text


  Move it from *Receiving* to *Accounts Payable*.

it will end up on the website as


  Move it from <b>Receiving</b> to <b>Accounts Payable</b>.

Given a String, text, containing zero or more usages of the italic and boldface shortcuts, translate it into HTML as demonstrated by the examples above. There will be an even number of underscores and of asterisks in text, respectively, and the spans of text enclosed by successive pairs of these characters will not overlap. To render a span of text in italics in HTML, you must start with the <i> tag and end with the </i> tag. For boldface text, start with <b> and end with </b>. After rendering all shortcuts in HTML, return the resulting text as a String.

Definition

Class:
bloggoShortcuts
Method:
expand
Parameters:
String
Returns:
String
Method signature:
String expand(String text)
(be sure your method is public)

Constraints

  • text is between 1 and 50 characters long, inclusive
  • the only characters allowed in text are the alphabetic characters 'a' to 'z' and 'A' to 'Z', the underscore '_', the asterisk '*', the space character, and the punctuation symbols ',', ';', '.', '!', '?', '-', '(', and ')'.
  • the underscore '_' occurs in text an even number of times
  • the asterisk '*' occurs in text an even number of times
  • no substring of text enclosed by a balanced pair of underscores or by a balanced pair of asterisks may contain any further underscores or asterisks

Examples

  1. "You _should_ see the new walrus at the zoo!"

    Returns: "You should see the new walrus at the zoo!"

    A walrus is a large, blubbery cousin of the seal.

  2. "Move it from *Accounts Payable* to *Receiving*."

    Returns: "Move it from Accounts Payable to Receiving."

    Notice that a boldface span may enclose several words.

  3. "I saw _Chelydra serpentina_ in *Centennial Park*."

    Returns: "I saw Chelydra serpentina in Centennial Park."

    One piece of text may include italics as well as boldface.

  4. " _ _ __ _ yabba dabba _ * dooooo * ****"

    Returns: " yabba dabba dooooo "

    Shortcuts may enclose spaces or nothing at all.

  5. "_now_I_know_*my*_ABC_next_time_*sing*it_with_me"

    Returns: "nowIknowmyABCnexttimesingitwithme"

  6. "**XU_h_bm .o QnmNI Y_ -!_ x___i vf_i***VL* s**"

    Returns: "XUhbm .o QnmNI Y -! xi vfiVL s"

  7. "O z s(P _I_** **__hA v?qcGGgNX***Fm LL*o _w__Mt _"

    Returns: "O z s(P I hA v?qcGGgNXFm LLo wMt "

  8. " ThqV*i* a*E u-, Pa*__yKp__*c e ****FW*q***vb* )"

    Returns: " ThqVi aE u-, PayKpc e FWqvb )"

  9. "_ay_) pO__ _ _CqZ_N X_* *. * bqw* HW_W___ ig_.u_"

    Returns: "ay) pO CqZN X . bqw HWW ig.u"

  10. "s zL I _ m_**-?* * jC_ _**_F dVOO_ Z__-_._ co Px"

    Returns: "s zL I m-? jC F dVOO Z-. co Px"

  11. " t_PlC,_ ____l V); * *Sb* *N Oh**X _p__k T_ h__"

    Returns: " tPlC, l V); Sb N OhX pk T h"

  12. "J-**_K __v_ZBn_m ___jD_p __k_S**qK CF*XO-t *(uRa"

    Returns: "J-K vZBnm jDp kSqK CFXO-t (uRa"

  13. "t I_vc_m__rf__ q? _st_**_ p_ -****_O _ ul _ _"

    Returns: "t Ivcmrf q? st p -O ul "

  14. "__*xsi;*SN** *;J* a_s_**L__C s u*iP * ei;K _x_"

    Returns: "xsi;SN ;J asLC s uiP ei;K x"

  15. "l*;w*j*! ZIYOm*__?ROco p_c y-___j*COE* WB _Ce Z_"

    Returns: "l;wj! ZIYOm?ROco pc y-jCOE WB Ce Z"

  16. "_q__!__m.sAU P_PS TuE_. _ __* RR*n;oT,, V *l,.*f"

    Returns: "q!m.sAU PPS TuE. RRn;oT,, V l,.f"

  17. " H _ T_E _;(d d _*(gT*FWlZM_uF_*V?**;E*B_ _ ; **"

    Returns: " H TE ;(d d (gTFWlZMuFV?;EB ; "

  18. "widq;_L_ ElLCP*;*_ nQ_ **J***NJJF ,(YQD?*__**_q _"

    Returns: "widq;L ElLCP; nQ JNJJF ,(YQD?q "

  19. " cnfG!_ZtM XQ,_TcW_p_-! dYb* *CH*oj Sv;c*w__F K__"

    Returns: " cnfG!ZtM XQ,TcWp-! dYb CHoj Sv;cwF K"

  20. "qh ?W_R_q i**_H! _**__V__Bj*RgprA*GUh __ X* *K(j"

    Returns: "qh ?WRq iH! VBjRgprAGUh X K(j"

  21. "z_l_ _gv_N *z* a *c *Yb J k**! E__J_ c_Dr"

    Returns: "zl gvN z a c Yb J k! EJ cDr"

  22. "T__l*ghj*v **k_eO)_I* R! .AR*W*Xj*___B_T MQ__ A"

    Returns: "Tlghjv keO)I R! .ARWXjBT MQ A"

  23. "**eCSbPB__f**_Z_** iGgM ,_x_ _pmWC A,_** O_iIsY _"

    Returns: "eCSbPBfZ iGgM ,x pmWC A, OiIsY "

  24. "**pf_ __b( VR_Dxnq_; k k _RKsQx_Gl?____- w f_ *?*"

    Returns: "pf b( VRDxnq; k k RKsQxGl?- w f ?"

  25. "**_eW _o F p_)CZ M K d , wmnfX_*vP* Y* *_!V z_**"

    Returns: "eW o F p)CZ M K d , wmnfXvP Y !V z"

  26. " M_ K_ X__j_U_qD Aj*c*lAV)_ EwgK_*DWmW***__"

    Returns: " M K XjUqD AjclAV) EwgKDWmW"

  27. "**Gl **ye_YFM_ _ jBRTbNB__sm_f**QMr *D*t _ w_"

    Returns: "Gl yeYFM jBRTbNBsmfQMr Dt w"

  28. "r*sb*w_Vn_vJ**gx_y _tX)j d__ - MU __D?kE NZnP-L**"

    Returns: "rsbwVnvJgxy tX)j d - MU D?kE NZnP-L"

  29. "* *aYp__fF-** _je,Lj MYl_____ *)L*n**E?VmvI_)! _"

    Returns: " aYpfF- je,Lj MYl )LnE?VmvI)! "

  30. "?*c *t** _n_Bq**Dm__***H* a _Z_,___Hz__R_w**,_v _"

    Returns: "?c t nBqDmH a Z,HzRw,v "

  31. "_ !_-.*s *rs;. J_n_ Z_ o-nvc)_Pf* *_ ___* *w,"

    Returns: " !-.s rs;. Jn Z o-nvc)Pf w,"

  32. "_W_b,Js*Z* m*z*o __ GT(ADX*C zuP*aZ* jfM*i__TA"

    Returns: "Wb,JsZ mzo GT(ADXC zuPaZ jfMiTA"

  33. "qUjf_ehyN_qPT*z*uP*FQ *GW)* * *ZO(P** * *! *"

    Returns: "qUjfehyNqPTzuPFQ GW) ZO(P ! "

  34. " d_I ?b.iiAFOZ _*q Ne * A __ni*** G p*GfQ* sF*"

    Returns: " dI ?b.iiAFOZ q Ne A ni G pGfQ sF"

  35. "* * Kj* *_._* yCV*___S ._*p *_DkU-ow_WYKv__ _ _"

    Returns: " Kj . yCVS .p DkU-owWYKv "

  36. ";;**nfy****-*M? vNu* _l_ _!HB_* ***h j* *L***yx*"

    Returns: ";;nfy-M? vNu l !HB h j Lyx"

  37. " eI*Cc *Z _ j__? __K _*H *M**f b***A *x F m__y"

    Returns: " eICc Z j? K H Mf bA x F my"

  38. "it?**l_ p_bi _ Z_lYb I_x _?_ _JN__ _v ,xM_eSa __"

    Returns: "it?l pbi ZlYb Ix ? JN v ,xMeSa "

  39. "_m sg _*)**D *W_ _*h*w__XjI lH?a fi_C f I_uh -r"

    Returns: "m sg )D W hwXjI lH?a fiC f Iuh -r"

  40. "m _Tnp__C_ (Jl__*;*jXk__*tjeK* *I*?h___kI_ F* ***"

    Returns: "m TnpC (Jl;jXktjeK I?hkI F "

  41. "Wz_b_tDN* jag * A_lF_q **Q; E ZE*X;,y(!J*U*B*__"

    Returns: "WzbtDN jag AlFq Q; E ZEX;,y(!JUB"

  42. "*BO.*P_QhBp_x** AXR__V*FV*Ken!.**_VL_ *HQ-UMYAx*"

    Returns: "BO.PQhBpx AXRVFVKen!.VL HQ-UMYAx"

  43. " _w_y*Ek*EclQ*o -W*_ ?mL_zq*R*i*i**C *m __oqn"

    Returns: " wyEkEclQo -W ?mLzqRiiC m oqn"

  44. " _H_ _uJ S _ ko *IvrNBF* ejy_ _m_uc_**xyK_ fZy_"

    Returns: " H uJ S ko IvrNBF ejy mucxyK fZy"

  45. "*,G*__. Q*NV* _I_* T *_L Q,iY_ l Gni_d_mX_ h_"

    Returns: ",G. QNV I T L Q,iY l GnidmX h"

  46. "_Bw-k, cm _**sN;__V*J(*FU-**_ _!_! _XpmbF***t*"

    Returns: "Bw-k, cm sN;VJ(FU- !! XpmbFt"

  47. "_nLbZ_uS_d P_ sl *(***_mV_ V_ .H_s__***knR*,__"

    Returns: "nLbZuSd P sl (mV V .HsknR,"

  48. ")sB*e?z*GQ f*** C * **Isd*bOs*uN*N BqWZK bC*zz* *"

    Returns: ")sBe?zGQ f C IsdbOsuNN BqWZK bCzz "

  49. " i_ _T_R_*c*Hf** p***dL n*?** X,?_X_W** _L _ b**"

    Returns: " i TRcHf pdL n? X,?XW L b"

  50. "q_WJ RK q C CZ_F*sDhk!R**i*_UY cM OaW_a*DPd L j*"

    Returns: "qWJ RK q C CZFsDhk!RiUY cM OaWaDPd L j"

  51. "_now_I_know_*my*_ABC_next_time_*sing*it_with_me"

    Returns: "nowIknowmyABCnexttimesingitwithme"

  52. "__________________________________________________"

    Returns: ""

  53. "You _should_ see the new walrus at the zoo!"

    Returns: "You should see the new walrus at the zoo!"

  54. "_now_I_know_*my*_ABC_next_me_**sing**it_with_me"

    Returns: "nowIknowmyABCnextmesingitwithme"

  55. "Move it from *Accounts Payable* to *Receiving*."

    Returns: "Move it from Accounts Payable to Receiving."

  56. "*test;*"

    Returns: "test;"

  57. "fdg dd_ sdfs_ , sdfsdf ,"

    Returns: "fdg dd sdfs , sdfsdf ,"

  58. "**"

    Returns: ""

  59. "**************************************************"

    Returns: ""

  60. "a__"

    Returns: "a"

  61. "____"

    Returns: ""


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: