You are viewing a single comment's thread. Return to all comments →
Here is my Solution. Let me know if you need any discussion about this.
Scanner scanner = new Scanner(System.in); int bitSetLength = scanner.nextInt(); int totalOperations = scanner.nextInt(); scanner.nextLine(); BitSet bs1 = new BitSet(bitSetLength); BitSet bs2 = new BitSet(bitSetLength); for (int i = 0; i < totalOperations; i++) { String line = scanner.nextLine(); String operation = line.split(" ")[0]; int oprand1 = Integer.parseInt(line.split(" ")[1]) ; int oprand2 = Integer.parseInt(line.split(" ")[2]); // System.out.println(operation + " , " + oprand1 + " " + oprand2 ); // String operation = if (operation.equals("AND")) { if(oprand1 == 1) bs1.and(bs2); else bs2.and(bs1); } else if (operation.equals("OR")) { if(oprand1 == 1) bs1.or(bs2); else bs2.or(bs1); } else if (operation.equals("XOR")) { if(oprand1 == 1) bs1.xor(bs2); else bs2.xor(bs1); } else if (operation.equals("SET")) { if (oprand1 == 1) bs1.set(oprand2); else bs2.set(oprand2); } else if (operation.equals("FLIP")) { if (oprand1 == 1) bs1.flip(oprand2); else bs2.flip(oprand2); } System.out.println(bs1.cardinality() + " " + bs2.cardinality() ); }
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 →
Here is my Solution. Let me know if you need any discussion about this.