-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJava BitSet.java
73 lines (65 loc) · 2 KB
/
Java BitSet.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
https://www.hackerrank.com/challenges/java-bitset/problem?isFullScreen=true
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
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 scanner = new Scanner(System.in);
int length = scanner.nextInt();
int operationNumber = scanner.nextInt();
BitSet bit1 = new BitSet(length);
BitSet bit2 = new BitSet(length);
while(operationNumber-->0){
String operationType = scanner.next();
int a = scanner.nextInt();
int b = scanner.nextInt();
if(operationType.equals("AND")){
if(a == 1){
bit1.and(bit2);
}
else {
bit2.and(bit1);
}
}
else if(operationType.equals("OR")){
if(a == 1){
bit1.or(bit2);
}
else {
bit2.or(bit1);
}
}
else if(operationType.equals("FLIP")){
if(a ==1){
bit1.flip(b);;
}
else {
bit2.flip(b);
}
}
else if (operationType.equals("SET")){
if(a ==1){
bit1.set(b);;
}
else {
bit2.set(b);
}
}
else if(operationType.equals("XOR")){
if(a ==1){
bit1.xor(bit2);;;
}
else {
bit2.xor(bit1);
}
}
System.out.println(bit1.cardinality()+" "+bit2.cardinality());
}
scanner.close();
}
}