Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BitShooter
- {
- static void Main(string[] args)
- {
- ulong number = ulong.Parse(Console.ReadLine());
- int countRight = 0;
- int countLeft = 0;
- for (int input = 0; input < 3; input++)
- {
- string[] secondLine = Console.ReadLine().Split();
- int shoot = int.Parse(secondLine[0]);
- int damage = int.Parse(secondLine[1]);
- int startBit = shoot - damage / 2;
- int endBit = shoot + damage / 2;
- // bit in range
- if (startBit < 0)
- {
- startBit = 0;
- }
- if (endBit > 63)
- {
- endBit = 63;
- }
- for (int i = startBit; i <= endBit; i++)
- {
- //Console.WriteLine(Convert.ToString(number, 2).PadLeft(63, '0'));
- if ((number & ((ulong)1 << i)) != 0)
- {
- number &= ~((ulong)1 << i);
- }
- }
- }
- //Console.WriteLine(Convert.ToString(number, 2).PadLeft(63, '0'));
- // count on the right
- for (int right = 0; right <= 31; right++)
- {
- if (((number >> right) & 1) == 1)
- {
- countRight++;
- }
- }
- // count on the left
- for (int left = 32; left < 64; left++)
- {
- if (((number >> left) & 1) == 1)
- {
- countLeft++;
- }
- }
- Console.WriteLine("left: {0}", countLeft);
- Console.WriteLine("right: {0}", countRight);
- }
- }
Add Comment
Please, Sign In to add comment