Mark-up Processor
InterviewTime limit1sMemory limit128 MB
Strip a small mark-up language from text: handle bold, italic, size, and a toggle that turns processing off, printing only the plain characters.
- Level
Medium5 of 10
- Topics
- String, Simulation, Implementation, Brute force
- Solved
- No attempts yet
Problem
Mark-up languages are computer languages that help format text files. Special keywords mark the text so that fonts, page styles, paragraph styles, and so on can be controlled. TeX, troff, and HTML are examples of mark-up languages.
Spell checking such texts is hard, so a dedicated processor is usually needed to strip the mark-up away and leave only the plain text for a spell checker to read. In this problem you must write such a processor for a small mark-up language: your program reads the marked-up text and prints the plain text with every mark-up applied and removed.
Every command begins with a \ character. If the character immediately after \ is not one of the recognized commands in the table below, then that character is printed as plain text. For instance, the mark-up \\ prints a single \.
The number after \s may contain a decimal point, so 12, 9.5, 11., and .5 are all valid numbers.
Because the output is plain text, the bold, italic, and size commands produce no visible characters; they are simply consumed. While processing is off, only \* is still recognized (so that processing can be turned back on); every other character, including \, is printed exactly as it appears.
Input
The input is plain text that contains mark-ups from the language above. When the input starts, mark-up processing is on. Process the input until end-of-file.
Output
Print the resulting plain text: the input with every mark-up command applied and stripped away. Keep all ordinary characters and line breaks exactly as they appear in the input.