Evaluating Circuit Expressions

Company: Zscalar_16nov

Difficulty: medium

Problem Statement

Evaluating Circuit Expressions Problem A circuit expression is a logic formula written in prefix form with square brackets. It is built from these symbols: [ and ] group an operation with its operands & is logical AND | is logical OR ! is logical NOT 1 is true and 0 is false Inside a pair of brackets the first symbol is either an operator or a single bit: [0] and [1] are the bit on their own. [&, x1, x2, ...] is the AND of its operands, of which there are at least two. [|, x1, x2, ...] is the OR of its operands, of which there are at least two. [!, x] is the negation of its one operand. Each operand is either a bare 0 , a bare 1 , or another bracketed expression. The whole expression is always enclosed in one outer pair of brackets. Commas and spaces only make the formula readable; they carry no meaning and are ignored. You are given q such expressions. Print the value of each. Input Format Line 1: the integer q , the number of expressions. The next q lines: one expression each