14271 - Transposed Expression   

Description

Veritas Ratio (Dr. Ratio) a member of Intelligentsia Guild wanted to test you in the way of math! He came up with a way to manipulate a series of expressions and you must transpose it after some series of manipulations. The process of transposing them involves the use of Stacks and Queues. You will be provided with simple mathematical expressions as input (e.g., 1+2*3, 2/1-1, 1+3*-). Your task involves implementing several functions: Insert, Print, Shift, Reverse, and Transpose. 

Insert [expression]

The command “Insert” will be used to insert the mathematical expressions. The length of the mathematical expressions will be in the range of 1 <= a <= 10, So it can be as short as “1” and as long as “1+2-1*2/2-” (Note that the expression can be illegal such as “1*”). In a single test case, all expressions will be of a similar length. There will be only 1-9 as Operands and + - * / as Operator, there is no negative number in the expressions so -1 means - and 1 not negative 1.

Print

The command “Print” will be used to print the whole input. Formatted such as it prints out data with the same sequence it got inserted, and also given a space after each character and a newline at the end. (e.g., “2 + 1 - 1 * 2 / 2 \n”)

Shift [i] [c]

The command “Shift” will be used to shift the Expression at index i to the left and then adds the character c from the right. (Note: c follows the same rules as the expression, only 1-9 and + - * / )

Reverse [i]

The command “Reverse” will be used to reverse the Expression at index i.

Transpose

The command “Transpose” will be used to transpose our expressions, formatted exactly the same as Print but transposed. 

End of explanation. Any question? No? Well..

Note:

- This is an exercise on using STL related to Stack and Queues. You can to try using Stack, Queue, Deque, Vector, Iterator and other STL to solve this problem.

- This exercise will not be scored, it is an optional exercise.

- If you have questions you can go to eLearn -> Homework 1 Question Board, post your question with the title [Exercise] Your question.

Input

It is guaranteed that the first line will always be the Insert command with each expression being 1 <= a <= 10 in length and the rest of the expression will have the same length as the first one.

The parameters of all command will always be valid (meaning it will never test out of index, or random alphabets).

Output

Command Print will output the formatted version of the data. 

Command Transpose will print the transposed version of the expressions.

Sample Input  Download

Sample Output  Download

Tags




Discuss