-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBitSets.java
57 lines (55 loc) · 1.67 KB
/
BitSets.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.*;
import java.util.*;
public class BitSets {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
BitSet b1 = new BitSet(n), b2 = new BitSet(n);
n = scan.nextInt();
String op;
int firstArg, secondArg;
for(int i = 0; i < n; i++) {
op = scan.next();
firstArg = scan.nextInt();
secondArg = scan.nextInt();
switch (op) {
case "AND":
if(firstArg == 1){
b1.and(b2);
} else {
b2.and(b1);
}
break;
case "OR":
if(firstArg == 1){
b1.or(b2);
} else {
b2.or(b1);
}
break;
case "XOR":
if(firstArg == 1){
b1.xor(b2);
} else {
b2.xor(b1);
}
break;
case "FLIP":
if(firstArg == 1){
b1.flip(secondArg);
} else {
b2.flip(secondArg);
}
break;
case "SET":
if(firstArg == 1){
b1.set(secondArg);
} else {
b2.set(secondArg);
}
break;
}
System.out.println(b1.cardinality() + " " + b2.cardinality());
}
}
}