Skip to content

Commit af7d05f

Browse files
authored
Add files via upload
1 parent 1541ba3 commit af7d05f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Diff for: Basics Java/src/Practice/Problems/BitSet.java

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.text.*;
4+
import java.math.*;
5+
import java.util.regex.*;
6+
7+
public class Solution {
8+
9+
public static void main(String[] args)
10+
{
11+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
12+
Scanner get = new Scanner(System.in);
13+
int n = get.nextInt();
14+
int m = get.nextInt();
15+
BitSet b1 = new BitSet(n);
16+
BitSet b2 = new BitSet(n);
17+
BitSet[] bitset = new BitSet[3];
18+
bitset[1] = b1;
19+
bitset[2] = b2;
20+
while ( 0 < m-- )
21+
{
22+
String op = get.next();
23+
int x = get.nextInt();
24+
int y = get.nextInt();
25+
switch (op)
26+
{
27+
case "AND":
28+
bitset[x].and(bitset[y]);
29+
break;
30+
case "OR":
31+
bitset[x].or(bitset[y]);
32+
break;
33+
case "XOR":
34+
bitset[x].xor(bitset[y]);
35+
break;
36+
case "FLIP":
37+
bitset[x].flip(y);
38+
break;
39+
case "SET":
40+
bitset[x].set(y);
41+
}
42+
System.out.printf("%d %d%n", b1.cardinality(), b2.cardinality());
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)