| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10955 | Prefix to truth table 2 |
|
| 10995 | Remove unnecessary parentheses |
|
| 11371 | Polynomial multiplication using linked list |
|
Description
Give a prefix Boolean expression, which only has at most 4 variables ‘A’, ‘B’, ‘C’, and ‘D’, and 2 operators, AND ‘&’ and OR ‘|’, print its truth table which output equal to 1.
For example, if input is "&|AB|CA", then result will be
A B C D output
0 1 1 0 1
0 1 1 1 1
1 0 0 0 1
1 0 0 1 1
1 0 1 0 1
1 0 1 1 1
1 1 0 0 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 1
Input
The input contains a sequences of prefix expression. It only has at most 4 variables ‘A’, ‘B’, ‘C’, and ‘D’, and 2 operators, AND ‘&’ and OR ‘|’. The length of prefix expression is shorter than 30.
Output
It has 4 variables 'A', 'B', 'C', 'D', and output, each variable is separated by a space.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an infix Boolean expression with parentheses, which has at most 4 variables ‘A’, ’B’, ‘C’, and ‘D’, and two operators ‘&’ and ‘|’. Please remove unnecessary parentheses and print the infix expression. Existence of unnecessary parentheses doesn’t affect the result of expression. For example,
(A&B)|(C&D) → A&B|(C&D)
(((A|B))) → A|B
Hint: You can combine two homework. Build a syntax tree and print the infix expression with necessary parentheses.
For OJ submission:
Step 1. Submit your main.c into the submission block.(Please choose C compiler)
Step 2. Check the results and debug your program if necessary.
Input
The input is an infix expression, which has at most 4 variables ‘A’, ’B’, ‘C’, and ‘D’, two operators ‘&’ and ‘|’, and parentheses. The length of the infix expression is less than 256.
Output
The output is an infix expression without unnecessary parentheses.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
You are required to use linked list to do the multiplication of two polynomials.
Input
The input contains two lines. Each lines presents a polynomial. The format of each line is looked like : "5 4 -3 2 1 0" which means polynomial "5x4-3x2+1x0".
Each polynomial must contain a constant term. (You can use this rule to determine whether the polynomial is end.)
For example, "-2 3 1 1 0 0" should be -2x3+1x1.
(The input polynomial should be arrangement in descending power.)
Output
Output the answer. Print a space character in the begining.
For example, if the input is
5 4 -3 2 1 0 (means 5x4-3x2+1)
-2 3 1 1 0 0 (means -2x3+1x1)
the output should be
" -10 7 11 5 -5 3 1 1" (which means -10x7+11x5-5x3+x).
If the value of coefficient is 0, you don't have to print it.
(The output polynomial should be arrangement in descending power.)