You are viewing a single comment's thread. Return to all comments →
static String line; static String[] input; static BitSet b1, b2; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); while ((line = in.readLine()) != null) { input = line.split(" "); if (line.startsWith("AND")) { if (input[1].equals("1")) { b1.and(b2); } else { b2.and(b1); } out.println(b1.cardinality() + " " + b2.cardinality()); } else if (line.startsWith("XOR")) { if (input[1].equals("1")) { b1.xor(b2); } else { b2.xor(b1); } out.println(b1.cardinality() + " " + b2.cardinality()); } else if (line.startsWith("OR")) { if (input[1].equals("1")) { b1.or(b2); } else { b2.or(b1); } out.println(b1.cardinality() + " " + b2.cardinality()); } else if (line.startsWith("SET")) { int index = Integer.parseInt(input[2]); if (input[1].equals("1")) { b1.set(index, true); } else { b2.set(index, true); } out.println(b1.cardinality() + " " + b2.cardinality()); } else if (line.startsWith("FLIP")) { int index = Integer.parseInt(input[2]); if (input[1].equals("1")) { b1.flip(index); } else { b2.flip(index); } out.println(b1.cardinality() + " " + b2.cardinality()); } else { b1 = new BitSet(Integer.parseInt(input[0])); b2 = new BitSet(Integer.parseInt(input[1])); } } out.flush(); in.close(); out.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 →