Advertisement
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;
- namespace waveBitsv2
- {
- class Program
- {
- static void Main(string[] args)
- {
- ulong number = ulong.Parse(Console.ReadLine());
- int count = 0;
- int longestCount = 0;
- int bestPosition = 0;
- int currentPosition = 0;
- bool seqStarted = false;
- int lastDigit = -1;
- int currentDigit;
- for (int i = 0; i < 64; i++)
- {
- currentDigit = CheckBit(number, i);
- if ((currentDigit == 1 && currentDigit != lastDigit) && (seqStarted == false))
- {
- count++;
- seqStarted = true;
- currentPosition = i;
- }
- else if (seqStarted == true && currentDigit != lastDigit)
- {
- count++;
- }
- else
- {
- if (longestCount < count)
- {
- longestCount = count;
- bestPosition = currentPosition;
- }
- count = 0;
- seqStarted = false;
- }
- lastDigit = currentDigit;
- }
- if (longestCount == 1)
- {
- Console.WriteLine("No waves found!");
- }
- else
- {
- number = RemoveBitV2(number, bestPosition, longestCount);
- Console.WriteLine(number);
- }
- //Console.WriteLine(longestCount);
- //Console.WriteLine(bestPosition);
- }
- public static int CheckBit(ulong number, int position)
- {
- if ((number & (ulong)1 << position) == 0)
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- public static ulong RemoveBitV2(ulong number, int position, int count)
- {
- ulong mask = 0;
- for (int i = 0; i < position; i++)
- {
- mask <<= 1;
- mask |= 1;
- }
- ulong rightBits = number & mask;
- number >>= position + count;
- number <<= position;
- return number |= rightBits;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement