Files
2019-03-15 13:47:54 +04:00

72 lines
1.4 KiB
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chelper;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class С extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
int n = in.nextInt();
int[] states = new int[10];
for (int i = 0; i < n; i++) {
char op = in.nextString().charAt(0);
int x = in.nextInt();
if (op == '&') {
x ^= 1023;
}
for (int j = 0; j < 10; j++) {
if (x % 2 == 1) {
switch (op) {
case '|':
states[j] = 1;
break;
case '&':
states[j] = 2;
break;
case '^':
states[j] ^= 3;
break;
}
}
x /= 2;
}
}
int alwaysZero = 0;
int alwaysOne = 0;
int xored = 0;
for (int i = 0; i < 10; i++) {
switch (states[i]) {
case 1:
alwaysOne += 1 << i;
break;
case 2:
alwaysZero += 1 << i;
break;
case 3:
xored += 1 << i;
break;
}
}
alwaysZero ^= 1023;
out.println(3);
out.println("| " + alwaysOne);
out.println("& " + alwaysZero);
out.println("^ " + xored);
}
}