#P9857. Prefix to Postfix Conversion

    ID: 23002 Type: Default 1000ms 256MiB

Prefix to Postfix Conversion

Prefix to Postfix Conversion

This problem requires you to convert an arithmetic expression given in prefix notation (also known as Polish notation) to its equivalent postfix notation (also known as Reverse Polish notation). In prefix notation, the operator precedes its two operands. For example, the prefix expression for the infix 3 + 4 is given by \( +\ 3\ 4 \). Similarly, the prefix representation for 5 - (4 - 2) is \( -\ 5\ -\ 4\ 2 \), while the prefix representation for (5 - 4) - 2 is \( -\ -\ 5\ 4\ 2 \).

Your task is to write a program that reads a single line containing a valid prefix expression and outputs the corresponding postfix expression. Note that the expression will only include binary operators and operands. The operators that can appear in the expression are \(+, -, *, /\). You may assume that the operands are valid numbers and that negative numbers will have their negative sign attached (e.g. "-5") which should be treated as operands, not an operator.

inputFormat

The input consists of a single line that contains a valid prefix expression. The tokens (operators and operands) are separated by spaces.

Example: + 3 4

outputFormat

Output the corresponding postfix expression in a single line, with tokens separated by a single space.

Example: For the input + 3 4, the output should be 3 4 +.

sample

+ 3 4
3 4 +