You are viewing a single comment's thread. Return to all comments →
Java 8
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int length = sc.nextInt(); BitSet b1 = new BitSet(length); BitSet b2 = new BitSet(length); BitSet [] b = {b1, b2}; int operations = sc.nextInt(); for(int i=0; i<operations; i++) { sc.nextLine(); String operation = sc.next(); int x = sc.nextInt() - 1; int y = sc.nextInt() - 1; if(operation.equals("AND")) { b[x].and(b[y]); } else if(operation.equals("OR")) { b[x].or(b[y]); } else if(operation.equals("XOR")) { b[x].xor(b[y]); } else if(operation.equals("FLIP")) { b[x].flip(y + 1); } else if(operation.equals("SET")) { b[x].set(y + 1); } System.out.println(b1.cardinality() + " " + b2.cardinality()); } sc.close(); }
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 →
Java 8