fork(4) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. private static int compare(BitSet lhs, BitSet rhs) {
  12. if (lhs.equals(rhs)) return 0;
  13. BitSet xor = (BitSet)lhs.clone();
  14. xor.xor(rhs);
  15. int firstDifferent = xor.length()-1;
  16. return rhs.get(firstDifferent) ? 1 : -1;
  17. }
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. BitSet a = new BitSet();
  21. BitSet b = new BitSet();
  22. BitSet c = new BitSet();
  23. a.set(5);
  24. b.set(500);
  25. c.set(73);
  26. System.out.println("a ? a = "+compare(a,a));
  27. System.out.println("a ? b = "+compare(a,b));
  28. System.out.println("a ? c = "+compare(a,c));
  29. System.out.println("b ? a = "+compare(b,a));
  30. System.out.println("b ? b = "+compare(b,b));
  31. System.out.println("b ? c = "+compare(b,c));
  32. System.out.println("c ? a = "+compare(c,a));
  33. System.out.println("c ? b = "+compare(c,b));
  34. System.out.println("c ? c = "+compare(c,c));
  35. }
  36. }
Success #stdin #stdout 0.1s 320256KB
stdin
Standard input is empty
stdout
a ? a = 0
a ? b = 1
a ? c = 1
b ? a = -1
b ? b = 0
b ? c = -1
c ? a = -1
c ? b = 1
c ? c = 0