Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BitBuilder
- {
- static void Main()
- {
- int number = int.Parse(Console.ReadLine());
- long result = number;
- while (true)
- {
- string p = Console.ReadLine();
- int position;
- if (p != "quit")
- {
- position = int.Parse(p);
- }
- else
- {
- break;
- }
- string command = Console.ReadLine();
- if (command == "flip")
- {
- result = (1 << position) ^ result;
- }
- else if (command == "remove")
- {
- long leftHalf = result >> position + 1;
- leftHalf = leftHalf << position;
- long rightHalf = result << 32 - position;
- rightHalf = rightHalf & 4294967295;
- rightHalf = rightHalf >> 32 - position;
- result = rightHalf | leftHalf;
- }
- else if (command == "insert")
- {
- long leftHalf = result >> position;
- leftHalf = leftHalf << position + 1;
- long rightHalf = result << 32 - position;
- rightHalf = rightHalf & 4294967295;
- rightHalf = rightHalf >> 32 - position;
- long combin = rightHalf | leftHalf;
- long mask = (long)1 << position;
- result = combin | mask;
- }
- }
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement