archangelmihail

DancingBits

Dec 4th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace DancingBits
  8. {
  9.     class DancingBits
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int set = int.Parse(Console.ReadLine());
  14.             int numbers = int.Parse(Console.ReadLine());
  15.             string concatenated = "";
  16.  
  17.             for (int i = 0; i < numbers; i++)
  18.             {
  19.                 int number = int.Parse(Console.ReadLine());
  20.                 string numberToString = Convert.ToString(number, 2);
  21.                 concatenated += numberToString;
  22.                 //Console.WriteLine(Convert.ToString(number,2));
  23.                 //Console.WriteLine(concatenated);
  24.             }
  25.             int count = 1;
  26.             int dance = 0;
  27.             byte settype = 1;
  28.             for (int i = 1; i < concatenated.Length; i++)
  29.             {
  30.                 if (concatenated[i] == '1' && settype == 1)
  31.                 {
  32.                     count++;
  33.                 }
  34.                 else if (concatenated[i] == '1' && settype == 0)
  35.                 {
  36.                     settype = 1;
  37.                     if (count == set)
  38.                     {
  39.                         dance++;
  40.                     }
  41.                     count = 1;
  42.                 }
  43.                 else if (concatenated[i] == '0' && settype == 0)
  44.                 {
  45.                     count++;
  46.                 }
  47.                 else if (concatenated[i] == '0' && settype == 1)
  48.                 {
  49.                     settype = 0;
  50.                     if (count == set)
  51.                     {
  52.                         dance++;
  53.                     }
  54.                     count = 1;
  55.                 }
  56.  
  57.             }
  58.             if (count == set)
  59.             {
  60.                 dance++;
  61.             }
  62.             Console.WriteLine(dance);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment