-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava_BitSet.java
More file actions
57 lines (56 loc) · 1.49 KB
/
Java_BitSet.java
File metadata and controls
57 lines (56 loc) · 1.49 KB
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.util.BitSet;
import java.util.Scanner;
//Mohajit Paul 20BCE10630
class JavaBitSet {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
BitSet b1 = new BitSet(N);
BitSet b2 = new BitSet(N);
for (int i = 0; i < M; i++) {
String op = sc.next();
int x = sc.nextInt();
int y = sc.nextInt();
switch (op) {
case "AND":
if (x == 1) {
b1.and(b2);
} else {
b2.and(b1);
}
break;
case "OR":
if (x == 1) {
b1.or(b2);
} else {
b2.or(b1);
}
break;
case "FLIP":
if (x == 1) {
b1.flip(y);
} else {
b2.flip(y);
}
break;
case "SET":
if (x == 1) {
b1.set(y);
} else {
b2.set(y);
}
break;
case "XOR":
if (x == 1) {
b1.xor(b2);
} else {
b2.xor(b1);
}
break;
}
System.out.println(b1.cardinality() + " " + b2.cardinality());
}
sc.close();
}
}