Advertisement
andkamen

salt and pepper BigInt impl

Feb 25th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package com.Ch1_ArraysAndStrings;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.math.BigInteger;
  7.  
  8. public class WeirdParser {
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.         BigInteger number = new BigInteger(reader.readLine());
  12.  
  13.         while (true) {
  14.             String[] input = reader.readLine().split(" ");
  15.  
  16.  
  17.             if ("end".equals(input[0])) {
  18.                 break;
  19.             }
  20.  
  21.             String command = input[0];
  22.             int count = Integer.parseInt(input[1]);
  23.  
  24.             if ("salt".equals(command)) {
  25.                 for (int i = 0; i < 64; i += count) {
  26.                     number = number.and(new BigInteger("1").shiftLeft(i).not());
  27.                 }
  28.             } else {
  29.                 for (int i = 0; i < 64; i += count) {
  30.                     number = number.setBit(i);
  31.                 }
  32.             }
  33.         }
  34.         System.out.println(number.toString());
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement