Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BitFlipper
- {
- static void Main()
- {
- ulong input = ulong.Parse(Console.ReadLine());
- string bit = Convert.ToString((long)input, 2).PadLeft(64,'0');
- string result = string.Empty;
- for (int i = 0; i < bit.Length; i++)
- {
- string tempOne = bit[i].ToString();
- string tempTwo = string.Empty;
- string tempThree = string.Empty;
- if (i + 1 < bit.Length)
- {
- tempTwo = bit[i + 1].ToString();
- }
- if (i + 2 < bit.Length)
- {
- tempThree = bit[i + 2].ToString();
- }
- if (tempOne.Equals("1") && tempTwo.Equals("1") && tempThree.Equals("1"))
- {
- result += "000";
- i += 2;
- continue;
- }
- else if ((tempOne.Equals("0") && tempTwo.Equals("0") && tempThree.Equals("0")))
- {
- result += "111";
- i += 2;
- continue;
- }
- else
- {
- result += bit[i];
- }
- }
- Console.WriteLine(Convert.ToUInt64(result,2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment