You are viewing a single comment's thread. Return to all comments →
Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); BitSet bs1 = new BitSet(n); BitSet bs2 = new BitSet(n); ArrayList<BitSet> bits = new ArrayList<>(); bits.add(bs1); bits.add(bs2); for (int i = 0; i < m ; i++) { String operator = in.next(); int pos1 = in.nextInt(); int pos2 = in.nextInt(); if (operator.equals("AND")) { bits.get(pos1-1).and(bits.get(pos2-1)); } else if (operator.equals("OR")) { bits.get(pos1-1).or(bits.get(pos2-1)); } else if (operator.equals("XOR")) { bits.get(pos1-1).xor(bits.get(pos2-1)); } else if (operator.equals("FLIP")) { bits.get(pos1-1).flip(pos2); } else if (operator.equals("SET")) { bits.get(pos1-1).set(pos2); } int sum1 = bits.get(0).cardinality(); int sum2 = bits.get(1).cardinality(); System.out.println(sum1+" "+sum2); }
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 →