This page is still under construction.

Parts of this page are still being built. What you see may change.

Markleft

Time limit1sMemory limit256 MB

Summary
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^threE becomes OneTWOthreE.
  • Text between two \ characters has a \ inserted before every double quote. Piglet \said "Hello"\ becomes Piglet 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# becomes Text with 1F C and 40.
  • Text between two < characters is reversed. This <be reversed<odd becomes This 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 @\<<#@ verbatim becomes This 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.

Examples1

  1. Example 1

    Input
    One^tWo^threE
    Piglet \said "Hello"\
    #Text with 31 12 and 64#
    This <be reversed<odd
    This is @\<<#@ verbatim
    ^aa<bcd<ee^
    abc^def^ghi^jkl^mno
    ab<cd^ef<gh<ij^kl<mn
    <#31#<
    #
    
    Expected output
    OneTWOthreE
    Piglet said \"Hello\"
    Text with 1F C and 40
    This desrever ebodd
    This is \<<# verbatim
    AADCBEE
    abcDEFghiJKLmno
    ablkJIGHFEdcmn
    F1