Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- class BitFlipper
- {
- static void Main()
- {
- ulong input = ulong.Parse(Console.ReadLine());
- string newstring = Convert.ToString((long)input, 2).PadLeft(64,'0');
- char[] bits = newstring.ToCharArray();
- for(int i = 0;i<62;i++)
- {
- if(bits[i] == '0' && bits[i+1] == '0' && bits[i+2] == '0')
- {
- bits[i] = '1';
- bits[i+1] = '1';
- bits[i+2] = '1';
- if (i < 62)
- {
- i += 2;
- }
- }
- else if(bits[i] == '1' && bits[i + 1] == '1' && bits[i + 2] == '1')
- {
- bits[i] = '0';
- bits[i + 1] = '0';
- bits[i + 2] = '0';
- if(i<62)
- {
- i += 2;
- }
- }
- }
- string result = "";
- foreach (char ch in bits)
- {
- result += ch;
- }
- ulong s = Convert.ToUInt64(result, 2);
- Console.WriteLine(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment