Advertisement
Guest User

Untitled

a guest
Feb 5th, 2015
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Task5
  6. {
  7.     static void Main()
  8.     {
  9.         int N = Int32.Parse(Console.ReadLine());
  10.         List<string> Numbers = new List<string>();
  11.  
  12.         for (int i = 0; i < N; i++)
  13.         {
  14.             Numbers.Add(Convert.ToString(long.Parse(Console.ReadLine()), 2).PadLeft(30, '0'));
  15.         }
  16.  
  17.         string concat = string.Empty;
  18.  
  19.         foreach (var item in Numbers)
  20.         {
  21.             concat += item;
  22.         }
  23.  
  24.         int longestZeros = LongestSequence(concat, true);
  25.         int longestOnes = LongestSequence(concat, false);
  26.  
  27.         Console.WriteLine(longestZeros);
  28.         Console.WriteLine(longestOnes);
  29.  
  30.     }
  31.  
  32.     static int LongestSequence(string str, bool isZero)
  33.     {
  34.         int longest = 0;
  35.         int length = 0;
  36.         int i;
  37.  
  38.         for (i = 0; i < str.Length; i++)
  39.         {
  40.             if (isZero ? str[i] == '0' : str[i] == '1')
  41.             {
  42.                 length++;
  43.             }
  44.             else
  45.             {
  46.                 if (length > longest)
  47.                 {
  48.                     longest = length;
  49.                 }
  50.                 length = 0;
  51.             }
  52.         }
  53.         if (length > longest)
  54.         {
  55.             longest = length;
  56.         }
  57.         return longest;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement