Markleft
Time limit1sMemory limit256 MB
The program converts each input line with nested markup rules for uppercase, quote escaping, decimal to hex, reversal, and verbatim copying.
- Level
Medium6 of 10
- Topics
- Stack, String, Simulation
- Solved
- No attempts yet
Problem
Markleft is a markup notation. Punctuation characters mark the text that a rule applies to.
- Text between two
^characters is converted to upper case.One^tWo^threEbecomesOneTWOthreE. - Text between two
\characters has a\inserted before every double quote.Piglet \said "Hello"\becomesPiglet said \"Hello\". - Text between two
#characters has every number converted to hexadecimal. One run of consecutive digits is one number, a number has at most 6 digits, and the hexadecimal form uses upper case letters and carries no leading zero.#Text with 31 12 and 64#becomesText with 1F C and 40. - Text between two
<characters is reversed.This <be reversed<oddbecomesThis desrever ebodd. - Text between two
@characters is copied verbatim, so markup inside it is ignored. There is therefore no way to put a@character into the output.This is @\<<#@ verbatimbecomesThis is \<<# verbatim.
Sections may be nested, but the nesting must be proper, the way brackets match. ^aa<bcd<ee^ becomes AADCBEE. The line One #reverse me ^uppercase me # and more^ is illegal because its nesting is improper.
A section closes at the first validly nested markleft character. abc^def^ghi^jkl^mno contains no nesting and becomes abcDEFghiJKLmno. Two sections of the same kind can still nest, and the effect is usually small but not always. ab<cd^ef<gh<ij^kl<mn becomes ablkJIGHFEdcmn.
The innermost section is processed first, so <#31#< becomes F1.
Input
The input is a sequence of lines of markleft text. Each line is at most 100 characters long and is formatted independently of the others. The markup on every line is valid. A line holding only # marks the end of the input.
Output
Print the formatted text of every input line, one line each, in input order. Print nothing for the closing # line.