BorislavBorisov

38.02.Dancing Bits решение със стринг

Oct 30th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. class DancingBits
  3. {
  4.     static void Main()
  5.     {
  6.         int k = int.Parse(Console.ReadLine());
  7.         int n = int.Parse(Console.ReadLine());
  8.         int len = 0, index = 0, sequence = 0;
  9.         char lastChar = ' ', charOne =' ';
  10.         string number = "";
  11.         for (int i = 0; i < n; i++)
  12.         {
  13.             int input = int.Parse(Console.ReadLine());
  14.             number += Convert.ToString(input, 2);
  15.         }
  16.         do
  17.         {
  18.             charOne = number[index];
  19.             if(lastChar == charOne)
  20.             {
  21.                 len++;
  22.             }
  23.             else
  24.             {
  25.                 if (len == k)
  26.                 {
  27.                     sequence++;
  28.                 }
  29.                 len = 1;
  30.             }
  31.             lastChar = charOne;
  32.             index++;
  33.         }while (index < number.Length);
  34.        
  35.         if(len == k)
  36.         {
  37.             sequence++;
  38.         }
  39.         Console.WriteLine(sequence);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment