forked from karterhhgg/JavaProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwenty.java
More file actions
60 lines (49 loc) · 1.52 KB
/
Twenty.java
File metadata and controls
60 lines (49 loc) · 1.52 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
58
59
60
/*
After each operation, print the respective number of set bits in BitSet and BitSet as space-separated integers on a new line.
Sample Input
5 4
AND 1 2
SET 1 4
FLIP 2 2
OR 2 1
Sample Output
0 0
1 0
1 1
1 2
*/
package HackerRank;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Twenty {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
BitSet[] bitsets = new BitSet[3];
bitsets[1] = new BitSet(n);
bitsets[2] = new BitSet(n);
for (int i = 0; i < m; i++) {
String op = sc.next();
int set1 = sc.nextInt();
int set2 = sc.nextInt();
if (op.equals("AND")) {
bitsets[set1].and(bitsets[set2]);
} else if (op.equals("OR")) {
bitsets[set1].or(bitsets[set2]);
} else if (op.equals("XOR")) {
bitsets[set1].xor(bitsets[set2]);
} else if (op.equals("FLIP")) {
bitsets[set1].flip(set2);
} else if (op.equals("SET")) {
bitsets[set1].set(set2);
}
System.out.println(bitsets[1].cardinality() + " " + bitsets[2].cardinality());
}
sc.close();
}
}