Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BitFlipper
- {
- static void Main()
- {
- ulong N = ulong.Parse(Console.ReadLine());
- string input = Convert.ToString((long)N, 2).PadLeft(64, '0');
- string output = "";
- for (int i = 0; i < input.Length - 2; i++)
- {
- if (input[i] == input[i + 1] && input[i + 1] == input[i + 2])
- {
- for (int j = 0; j < 3; j++)
- {
- if (input[i] == '1')
- {
- output += '0';
- }
- else
- {
- output += '1';
- }
- }
- //for (int j = i; j <= i + 2; j++)
- //{
- // if (input[j] == '0')
- // {
- // output += '1';
- // }
- // else
- // {
- // output += '0';
- // }
- //}
- i += 2;
- }
- else
- {
- output += input[i];
- }
- }
- int lengthPast = input.Length - output.Length;//добавям ако има останали в края
- if (lengthPast != 0)
- {
- for (int i = lengthPast; i > 0; i--)
- {
- output += input[input.Length - i];
- }
- }
- //if (input.Length > output.Length)
- //{
- // for (int i = output.Length; i < input.Length; i++)
- // {
- // output += input[i];
- // }
- //}
- Console.WriteLine(Convert.ToUInt64(output,2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment