0% found this document useful (0 votes)
19 views1 page

Practice Problem - Transform The Expression in Stacks and Queues

The document describes a practice problem involving the transformation of algebraic expressions into Reverse Polish Notation (RPN). It outlines the input format, which includes a number of test cases and expressions to be converted, and specifies the output format as RPN expressions. A sample input and output are provided to illustrate the transformation process.

Uploaded by

Asif Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Practice Problem - Transform The Expression in Stacks and Queues

The document describes a practice problem involving the transformation of algebraic expressions into Reverse Polish Notation (RPN). It outlines the input format, which includes a number of test cases and expressions to be converted, and specifies the output format as RPN expressions. A sample input and output are provided to illustrate the transformation process.

Uploaded by

Asif Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1/26/25, 4:14 PM Practice problem - Transform the Expression in Stacks and Queues

Practice problem - Transform the Expression


Reverse Polish Notation (RPN) is a mathematical notation where every
operator follows all of its operands. For instance, to add three and four, one
would write "3 4 +" rather than "3 + 4". If there are multiple operations, the
operator is given immediately after its second operand; so the expression
written "3 − 4 + 5" would be written "3 4 − 5 +" first subtract 4 from 3, then
add 5 to that.

Reverse polish notations are easier to parse for computers and you don't
need parentheses to denote precedence of operations.

Transform the algebraic expression with brackets into RPN form.

You can assume that for the test cases below only single letters will be used,
brackets [] will not be used and each expression has only one RPN form (no
expressions like a*b*c)

Input Format
The first line contains t, the number of test cases (less then 100).
Followed by t lines, containing an expression to be translated to RPN form,
where the length of the expression is less then 400.

Output Format
The expressions in RPN form, one per line.

Sample 1:

Input Output
3 abc*+
(a+(b*c)) ab+zx+*
((a+b)*(z+x)) at+bac++cd+^*
((a+t)*((b+(a+c))^(c+d)))

Explanation:
Test case 1: (a+(b*c))

Start with innermost brackets: b*c becomes bc* .


https://www.codechef.com/learn/course/stacks-and-queues/LSTACKS02/problems/STACK07 1/1

You might also like