Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BitBuilder
- {
- static void Main(string[] args)
- {
- long number = long.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- while (command != "quit")
- {
- int position = int.Parse(command);
- command = Console.ReadLine();
- long mask = 0; // Правим Маска и за дазапазим битовете
- //
- for (int i = 0; i < position; i++) //
- { //
- mask <<= 1; //
- mask |= 1; //
- }
- long rightBits = number & mask; //
- switch (command)
- {
- case "flip":
- number ^= 1 << position;
- break;
- case "remove":
- number >>= position + 1;
- number <<= position;
- number |= rightBits;
- break;
- case "insert":
- number >>= position;
- number <<= position + 1;
- number |= (long)1 << position;
- number |= rightBits;
- break;
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(number);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment