- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0040.java
More file actions
Latest commit
63 lines (57 loc) · 1.29 KB
/
Copy pathHackerrankJava0040.java
File metadata and controls
63 lines (57 loc) · 1.29 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
61
62
63
importjava.util.BitSet;
importjava.util.Scanner;
publicclassHackerrankJava0040 {
publicstaticvoidmain(String[] args) {
// Java BitSet
// https://www.hackerrank.com/challenges/java-bitset/problem?isFullScreen=true
Scannerscanner = newScanner(System.in);
intsizeOfSets = scanner.nextInt();
intnumberOfOperations = scanner.nextInt();
BitSetbitSet1 = newBitSet(sizeOfSets);
BitSetbitSet2 = newBitSet(sizeOfSets);
for (inti = 0; i < numberOfOperations; i++) {
Stringoperation = scanner.next();
intset1 = scanner.nextInt();
intset2 = scanner.nextInt();
switch (operation) {
case"AND":
if (set1 == 1) {
bitSet1.and(bitSet2);
} else {
bitSet2.and(bitSet1);
}
break;
case"OR":
if (set1 == 1) {
bitSet1.or(bitSet2);
} else {
bitSet2.or(bitSet1);
}
break;
case"XOR":
if (set1 == 1) {
bitSet1.xor(bitSet2);
} else {
bitSet2.xor(bitSet1);
}
break;
case"FLIP":
if (set1 == 1) {
bitSet1.flip(set2);
} else {
bitSet2.flip(set2);
}
break;
case"SET":
if (set1 == 1) {
bitSet1.set(set2);
} else {
bitSet2.set(set2);
}
break;
}
System.out.println(bitSet1.cardinality() + " " + bitSet2.cardinality());
}
scanner.close();
}
}