Advertisement
stanevplamen

01.7.4.4.DancingBits

May 15th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. //using System.Numerics;
  3.  
  4. class DancingBits
  5. {
  6.     static void Main()
  7.     {
  8.         int equalBitsK = int.Parse(Console.ReadLine());
  9.         int numbersN = int.Parse(Console.ReadLine());
  10.         string binarySum = null;
  11.  
  12.  
  13.         for (int i = 1; i <= numbersN; i++)
  14.         {
  15.             int usedNumber = int.Parse(Console.ReadLine());
  16.             string binaryValue = Convert.ToString(usedNumber, 2);
  17.             binarySum = binarySum + binaryValue;
  18.         }
  19.         char[] charArr = binarySum.ToCharArray();
  20.         int counterOne = 1;
  21.         int counterTwo = 0;
  22.         int counterThree = 0;
  23.  
  24.         int[] intArray = new int[charArr.Length];
  25.  
  26.         for (int c = 0; c < (charArr.Length); c++)
  27.         {
  28.             counterThree++;
  29.             intArray[c] = (int)Char.GetNumericValue(charArr[c]);
  30.         }
  31.         for (int c = 0; c < (charArr.Length-1); c++)
  32.         {
  33.  
  34.             if (intArray[c] == intArray[c+1])
  35.             {
  36.                 counterOne++;
  37.             }
  38.             else if (intArray[c] != intArray[c + 1])
  39.             {
  40.                 if (equalBitsK == counterOne)
  41.                 {
  42.                     counterTwo++;
  43.                 }
  44.                 counterOne = 1;
  45.             }
  46.             if (counterThree == c + 2)
  47.             {
  48.                 if (equalBitsK == counterOne)
  49.                 {
  50.                     counterTwo++;
  51.                 }
  52.             }
  53.         }
  54.         Console.WriteLine(counterTwo);          
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement