bloggoShortcuts
SRM 214 · 2004-10-06 · by Eeyore
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
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
"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.
"Move it from *Accounts Payable* to *Receiving*." Returns: "Move it from Accounts Payable to Receiving."
Notice that a boldface span may enclose several words.
"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.
" _ _ __ _ yabba dabba _ * dooooo * ****" Returns: " yabba dabba dooooo "
Shortcuts may enclose spaces or nothing at all.
"_now_I_know_*my*_ABC_next_time_*sing*it_with_me" Returns: "nowIknowmyABCnexttimesingitwithme"
Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class bloggoShortcuts with a public method string expand(string text) · 61 test cases · 2 s / 256 MB per case