svetlozar_kirkov

Bit Builder (100/100)

Nov 14th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace BitBuilder
  5. {
  6.     class BitBuilder
  7.     {
  8.         static void Main()
  9.         {
  10.             ulong n = ulong.Parse(Console.ReadLine());
  11.             string binary = Convert.ToString((int)n, 2).PadLeft(64,'0');
  12.             List<ulong> binaryList = new List<ulong>();
  13.            
  14.             for (int i = 0; i < binary.Length; i++)
  15.             {
  16.                 binaryList.Add(Convert.ToUInt64(binary[i].ToString()));
  17.             }
  18.            
  19.             binaryList.Reverse();
  20.            
  21.             while (true)
  22.             {
  23.                 string position = Console.ReadLine();
  24.                 if (position == "quit")
  25.                 {
  26.                     break;
  27.                 }
  28.                 string action = Console.ReadLine();
  29.                 if (action == "flip")
  30.                 {
  31.                     if (binaryList[Convert.ToInt32(position.ToString())]==0)
  32.                     {
  33.                         binaryList[Convert.ToInt32(position.ToString())] = 1;
  34.                     }
  35.                     else if (binaryList[Convert.ToInt32(position.ToString())]==1)
  36.                     {
  37.                         binaryList[Convert.ToInt32(position.ToString())] = 0;
  38.                     }
  39.                 }
  40.                 else if (action == "insert")
  41.                 {
  42.                     binaryList.Insert(Convert.ToInt32(position.ToString()),1);
  43.                 }
  44.                 else if (action == "remove")
  45.                 {
  46.                     binaryList.RemoveAt(Convert.ToInt32(position.ToString()));
  47.                 }
  48.                 else if (action == "skip")
  49.                 {
  50.                     continue;
  51.                 }
  52.             }
  53.             binaryList.Reverse();
  54.             Console.WriteLine(Convert.ToUInt64(string.Join("", binaryList), 2));
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment