Advertisement
Guest User

Untitled

a guest
May 25th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package _01_DHARMA_Sonar_Fence;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10.      
  11.         while (true) {
  12.             String input = br.readLine();
  13.             if ("Reprogram".equals(input)){
  14.                 break;
  15.             }    
  16.             int num = Integer.parseInt(input);
  17.  
  18.             for (int i = 0; i < 32 - 1; i++) {
  19.  
  20.                 int firstDigit = (int) (num >> (31 - i) & 1);
  21.                 int secondDigit = (int) (num >> (31 - i - 1) & 1);
  22.  
  23.                 if (firstDigit == secondDigit) {
  24.                     int position = 31 - i;
  25.                     num = num ^ 1 << (position);
  26.                     num = num ^ 1 << (position - 1);
  27.  
  28.                     i += 1;
  29.                 }
  30.             }  
  31.             System.out.println(Integer.toUnsignedString(num));  
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement