#P1575. Bobo's Boolean Operation Challenge
Bobo's Boolean Operation Challenge
Bobo's Boolean Operation Challenge
Little bobo has become fascinated with logical operations. However, the calculations have become so confusing that he cannot figure them out himself. He needs your help to evaluate boolean expressions.
You will be given two boolean values (where 0 represents false and 1 represents true) and an operator. The operator will be one of the following: AND, OR, or XOR. Your task is to compute the result of the operation. Use the standard definitions:
- \(a \land b\): true if both \(a\) and \(b\) are true
- \(a \lor b\): true if at least one of \(a\) or \(b\) is true
- \(a \oplus b\): true if exactly one of \(a\) or \(b\) is true
The output should be a single line with the result (0 or 1) for each test case.
inputFormat
The first line contains an integer T (\(T \ge 1\)), representing the number of test cases. Each of the next T lines contains two integers and a string, separated by spaces. The integers a and b are either 0 or 1, and the string op will be one of "AND", "OR", or "XOR".
outputFormat
For each test case, output a single line containing the result of applying the operator on the two boolean values. The result should be 1 if the expression is true, and 0 if it is false.
sample
3
1 0 AND
1 1 OR
0 1 XOR
0
1
1
</p>