We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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 in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
BitSet b1 = new BitSet(n);
BitSet b2 = new BitSet(n);
HashMap<Integer, BitSet> bitSetHM = new HashMap<Integer, BitSet>() {{
put(1, b1);
put(2, b2);
}};
for (int i = 0; i < m; i++) {
String cmd = in.next();
int p = in.nextInt();
int q = in.nextInt();
switch(cmd) {
case "AND":
bitSetHM.get(p).and(bitSetHM.get(q));
break;
case "OR":
bitSetHM.get(p).or(bitSetHM.get(q));
break;
case "XOR":
bitSetHM.get(p).xor(bitSetHM.get(q));
break;
case "FLIP":
bitSetHM.get(p).flip(q);
break;
case "SET":
bitSetHM.get(p).set(q);
break;
}
System.out.println(bitSetHM.get(1).cardinality()+" "+ bitSetHM.get(2).cardinality());
if(in.hasNextLine()) {
in.nextLine();
}
}
in.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java BitSet
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
}