Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace BitBuilder
- {
- class BitBuilder
- {
- static void Main()
- {
- ulong n = ulong.Parse(Console.ReadLine());
- string binary = Convert.ToString((int)n, 2).PadLeft(64,'0');
- List<ulong> binaryList = new List<ulong>();
- for (int i = 0; i < binary.Length; i++)
- {
- binaryList.Add(Convert.ToUInt64(binary[i].ToString()));
- }
- binaryList.Reverse();
- while (true)
- {
- string position = Console.ReadLine();
- if (position == "quit")
- {
- break;
- }
- string action = Console.ReadLine();
- if (action == "flip")
- {
- if (binaryList[Convert.ToInt32(position.ToString())]==0)
- {
- binaryList[Convert.ToInt32(position.ToString())] = 1;
- }
- else if (binaryList[Convert.ToInt32(position.ToString())]==1)
- {
- binaryList[Convert.ToInt32(position.ToString())] = 0;
- }
- }
- else if (action == "insert")
- {
- binaryList.Insert(Convert.ToInt32(position.ToString()),1);
- }
- else if (action == "remove")
- {
- binaryList.RemoveAt(Convert.ToInt32(position.ToString()));
- }
- else if (action == "skip")
- {
- continue;
- }
- }
- binaryList.Reverse();
- Console.WriteLine(Convert.ToUInt64(string.Join("", binaryList), 2));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment