# | Problem | Pass Rate (passed user / total user) |
---|---|---|
11891 | Postfix to Syntax Tree |
|
13505 | String Calculator(class) 2 |
|
Description
The input is a postfix Boolean expression, which has at most four variables ‘A’, ’B’, ‘C’, and ‘D’, and two operators ‘&’ and ‘|’. The task is to use this postfix expression to construct a syntax tree, and print the corresponding infix expression. For example, if the input is
AB|CD&&A|
then its syntax tree should be
The corresponding infix expression with parenthesis is
A|B&(C&D)|A
You need to implement the function "constructTree()" based on the two files "main.c" and "function.h" given below.
For OJ submission:
You only need to copy and paste the code of your "function.c" into the submission block. Make sure you choose C compiler.
HINT :
Please read partial judge code first. We help you dealing with input :)
Input
The first line is a number N indicating the number of test cases. The next N lines contain the prefix Boolean expressions.
Output
The output contains N lines of the infix expressions with necessary parentheses.
Sample Input Download
Sample Output Download
Partial Judge Code
11891.cPartial Judge Header
11891.hTags
Discuss
Description
In this problem, you need to finish a string calculator.
The calculator has three string operators:
- a + b: Concatenate the string b after the string a.
- a - b: If string b has appeared in string a, delete the first appearance of b in a, otherwise the result is "error".
- a @ b:
If b is an integer, a should be right-shifted b times, according to the following letter order: 0, 1, 2, ... , 9, a, b, ..., z. Otherwise the result is "error".- For example:
a = abcxyz, b = 3, result = def012 (that is, 'a'->'d', 'b'->'e', ..., and 'z'->'2'.)
- For example:
Input
The first line contains an integer N
The following N lines, each line contains two string a b and a operation op.
testcases:
(3/10) 1 <= N <= 100, 1 <= |a|, |b| <= 100, op = '+'
(3/10) 1 <= N <= 100, 1 <= |a|, |b| <= 100, op = '-'
(4/10) 1 <= N <= 100, 1 <= |a|, |b| <= 100, op = '@'
Output
The output contains N lines.
For each a b op, output the calculation result.