IRusev

Problem 8. * Count of Equal Bit Pairs

Sep 9th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CountOfEqualBitPairs {
  4.  
  5. static int count = 0;
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner input = new Scanner(System.in);
  10. int number = input.nextInt();
  11.  
  12. for (int i = 31; i > 0; i--) {
  13. int temp = 1 << i & number;
  14. if (temp == 0) {
  15. continue;
  16. } else {
  17. for (int j = i; j >= 0; j--){
  18. int t = (3 << j) & number;
  19.  
  20. int t1 = number>>j & 1;
  21. int t2 = number>>j-1 &1;
  22.  
  23. if (t >> j == 3) {
  24. count++;
  25.  
  26. }else if(t1 == 0 && t2 == 0){
  27. count++;
  28. }
  29.  
  30. }
  31. break;
  32. }
  33. }
  34. input.close();
  35. System.out.println(count);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment