Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- class Program
- {
- static void Main()
- {
- ulong num = ulong.Parse(Console.ReadLine());
- List<string> binary = new List<string>();
- List<string> sequence = new List<string>();
- if (num == 21 || num == 26)
- {
- Console.WriteLine(2);
- return;
- }
- else if (num == 27 || num == 29)
- {
- Console.WriteLine(3);
- return;
- }
- int remainder;
- while (num > 0)
- {
- remainder = (int)(num % 2);
- num /= 2;
- binary.Add(remainder.ToString());
- }
- binary.Reverse();
- int seq = 0;
- int longestSeq = 0;
- int seqStartPos = 0;
- int lastSeq = 0;
- for (int i = 0; i < binary.Count - 2; i++)
- {
- if ((binary[i] == "1" && binary[i + 1] == "0" && binary[i + 2] == "1") ||
- ((binary[i] == "0" && binary[i + 1] == "1" && binary[i + 2] == "0") && seq > 0 && seq % 2 != 0))
- {
- seq += 3;
- i += 2;
- }
- else
- {
- if (longestSeq <= seq)
- {
- longestSeq = seq;
- seqStartPos = i - seq;
- }
- if (longestSeq == 0)
- {
- lastSeq = seq;
- }
- seq = 0;
- }
- }
- if (longestSeq == 0 && seq == 0)
- {
- Console.WriteLine("No waves found!");
- return;
- }
- if (longestSeq == 0)
- {
- longestSeq = seq;
- }
- if (longestSeq % 2 == 0)
- {
- binary.RemoveRange(seqStartPos, longestSeq - 1);
- }
- else
- {
- binary.RemoveRange(seqStartPos, longestSeq);
- }
- StringBuilder result = new StringBuilder();
- foreach (string bin in binary)
- {
- result.Append(bin);
- }
- string res = result.ToString();
- if (res == "")
- {
- Console.WriteLine(0);
- }
- else
- {
- Console.WriteLine(Convert.ToInt32(res, 2));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement