Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class WaveBits
- {
- static void Main()
- {
- ulong N = ulong.Parse(Console.ReadLine());
- bool isFindSeq = false, isStartIndex = true;
- int counter = 1, bestCounter = 0, startDelete = 0, otherStartDelete = 0;
- for (int i = 64; i >= 0; i--)
- {
- if((N & ((ulong)1 << i)) != 0 && (N & ((ulong)1 << i - 1)) == 0
- && (N & ((ulong)1 << i - 2)) != 0)
- {
- counter += 2;
- if(isStartIndex)
- {
- isStartIndex = false;
- startDelete = i;
- }
- i--;
- }
- if(i == 0 && bestCounter > counter)
- {
- startDelete = otherStartDelete;
- }
- else if((N & ((ulong)1 << i)) != 0 && !(isFindSeq) && counter > 1)
- {
- if (bestCounter <= counter)
- {
- bestCounter = counter;
- isStartIndex = true;
- otherStartDelete = startDelete;
- }
- counter = 1;
- }
- }
- if(bestCounter == 0)
- {
- Console.WriteLine("No waves found!");
- return;
- }
- string newNumber = null;
- for (int i = 63; i >= 0; i--)
- {
- if(i == startDelete)
- {
- i++;
- while(bestCounter > 0)//пор този начин не броя намерената редица
- {
- bestCounter--;
- i--;
- }
- }
- else if((N & ((ulong)1 << i)) != 0)
- {
- newNumber += '1';
- }
- else if((N & ((ulong)1 << i)) == 0)
- {
- newNumber += '0';
- }
- }
- Console.WriteLine(Convert.ToUInt64(newNumber, 2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment