Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BitBuilder
- {
- class BitBuilder
- {
- static void Main(string[] args)
- {
- long number = Convert.ToInt64(Console.ReadLine());
- string action = "";
- int possition = 0;
- long mask = 0;
- while (true)
- {
- string possitionString = (Console.ReadLine());
- if (possitionString == "quit")
- {
- Console.WriteLine(number);
- return;
- }
- else
- {
- possition = Convert.ToInt32(possitionString);
- }
- action = Console.ReadLine();
- string maskAsString = new string('1', (int)possition);
- if (possition != 0)
- {
- mask = Convert.ToInt64(maskAsString, 2);
- }
- if (action == "flip")
- {
- number = number ^ (1 << possition);
- }
- long rightBits = (long)(number & mask);
- if (action == "insert")
- {
- number = number >> possition;
- number = number << (possition + 1);
- number = number | ((long)1 << possition);
- number = number | rightBits;
- }
- if (action == "remove")
- {
- number = number >> (possition + 1);
- number = number << possition;
- number = (long)number | rightBits;
- }
- if (action == "skip")
- {
- continue;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement