Advertisement
fbinnzhivko

BitShooter2

Apr 21st, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. class BitShooter2
  3. {
  4.     static void Main()
  5.     {
  6.         const int BITS = 64;
  7.  
  8.         ulong inputBits = ulong.Parse(Console.ReadLine());
  9.         ulong shootedBits = 0;
  10.         for (int i = 0; i < 3; i++)
  11.         {
  12.             string shoot = Console.ReadLine();
  13.             string[] shootDetails = shoot.Split(' ');
  14.             int shootCenter = int.Parse(shootDetails[0]);
  15.             int shootSize = int.Parse(shootDetails[1]);
  16.             int startBit = shootCenter - shootSize / 2;
  17.             int endBit = shootCenter + shootSize / 2;
  18.             for (int bit = startBit; bit <= endBit; bit++)
  19.             {
  20.                 if (bit >= 0 && bit < BITS)
  21.                 {
  22.                     shootedBits = shootedBits | ((ulong)1 << bit);
  23.                 }
  24.             }
  25.         }
  26.         ulong aliveBits = inputBits & (~shootedBits);
  27.  
  28.         //Console.WriteLine(Convert.ToString((long)inputBits, 2).PadLeft(64,'0'));
  29.         //Console.WriteLine(Convert.ToString((long)~shootedBits, 2).PadLeft(64, '0'));
  30.         //Console.WriteLine(Convert.ToString((long)aliveBits, 2).PadLeft(64, '0'));
  31.  
  32.         ulong rightBits = 0;
  33.         for (int i = 0; i < BITS / 2; i++)
  34.         {
  35.             rightBits += aliveBits & 1;
  36.             aliveBits >>= 1;
  37.         }
  38.  
  39.         ulong leftBits = 0;
  40.         for (int i = 0; i < BITS / 2; i++)
  41.         {
  42.             leftBits += aliveBits & 1;
  43.             aliveBits >>= 1;
  44.         }
  45.  
  46.         Console.WriteLine("left: " + leftBits);
  47.         Console.WriteLine("right: " + rightBits);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement