Alexander7337

BitShooter

Feb 2nd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2.  
  3.     class BitShooter
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             ulong number = ulong.Parse(Console.ReadLine());
  8.             int countRight = 0;
  9.             int countLeft = 0;
  10.  
  11.             for (int input = 0; input < 3; input++)
  12.             {
  13.                 string[] secondLine = Console.ReadLine().Split();
  14.                 int shoot = int.Parse(secondLine[0]);
  15.                 int damage = int.Parse(secondLine[1]);
  16.                 int startBit = shoot - damage / 2;
  17.                 int endBit = shoot + damage / 2;
  18.  
  19.                 // bit in range
  20.                 if (startBit < 0)
  21.                 {
  22.                     startBit = 0;
  23.                 }
  24.                 if (endBit > 63)
  25.                 {
  26.                     endBit = 63;
  27.                 }
  28.  
  29.                 for (int i = startBit; i <= endBit; i++)
  30.                 {
  31.                     //Console.WriteLine(Convert.ToString(number, 2).PadLeft(63, '0'));
  32.                     if ((number & ((ulong)1 << i)) != 0)
  33.                     {
  34.                         number &= ~((ulong)1 << i);
  35.                     }
  36.                 }
  37.             }
  38.             //Console.WriteLine(Convert.ToString(number, 2).PadLeft(63, '0'));
  39.             // count on the right
  40.             for (int right = 0; right <= 31; right++)
  41.             {
  42.                 if (((number >> right) & 1) == 1)
  43.                 {
  44.                     countRight++;
  45.                 }
  46.             }
  47.             // count on the left
  48.             for (int left = 32; left < 64; left++)
  49.             {
  50.                 if (((number >> left) & 1) == 1)
  51.                 {
  52.                     countLeft++;
  53.                 }
  54.             }
  55.  
  56.             Console.WriteLine("left: {0}", countLeft);
  57.             Console.WriteLine("right: {0}", countRight);
  58.         }
  59.     }
Add Comment
Please, Sign In to add comment