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;
- using System.Numerics;
- namespace _05.Problem
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- StringBuilder sb = new StringBuilder();
- long[] numbers = new long[n];
- string[] binary = new string[n];
- int count = 30;
- for (int i = 0; i < n; i++)
- {
- numbers[i] = long.Parse(Console.ReadLine());
- }
- for (int i = 0; i < numbers.Length; i++)
- {
- binary[i] = Convert.ToString(numbers[i], 2);
- int difference = -1;
- if (binary[i].Length >= 30)
- {
- count = 30;
- }
- else
- {
- count = binary[i].Length;
- difference = 30 - count;
- for (int k = 0; k < difference; k++)
- {
- sb.Append("0");
- }
- }
- difference = 30 - count;
- for (int k = 0; k < count; k++)
- {
- sb.Append(binary[i][k] - '0');
- }
- }
- string bits = sb.ToString();
- int zerosCount = 0;
- int onesCount = 0;
- int longestZeroCount = 0;
- int longestOnesCount = 0;
- for (int i = 0; i < bits.Length; i++)
- {
- if ((bits[i] - '0') == 0)
- {
- zerosCount++;
- if (longestOnesCount < onesCount)
- {
- longestOnesCount = onesCount;
- }
- onesCount = 0;
- }
- else if ((bits[i] - '0') == 1)
- {
- onesCount++;
- if (longestZeroCount < zerosCount)
- {
- longestZeroCount = zerosCount;
- }
- zerosCount = 0;
- }
- if (onesCount > longestOnesCount)
- {
- longestOnesCount = onesCount;
- }
- if (zerosCount > longestZeroCount)
- {
- longestZeroCount = zerosCount;
- }
- }
- Console.WriteLine(longestZeroCount);
- Console.WriteLine(longestOnesCount);
- }
- }
- }
- // 100
- // 1073741823
- // 1073741823
- // 1073741823
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement