Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class DancingBits
- {
- static void Main()
- {
- int k = 3;
- int n = 4;
- string allBits = "";
- for (int i = 0; i < n; i++)
- {
- int input = int.Parse(Console.ReadLine());
- allBits += Convert.ToString(input, 2);
- }
- allBits = "*" + allBits + "*";
- string ones = new string('1', k);
- int oneCount = 0;
- int index = -1;
- while(true)
- {
- index = allBits.IndexOf(ones, index + 1);
- if(index == -1)
- {
- break;
- }
- if(allBits[index + k - 1] != allBits[index + k]
- && allBits[index - 1] != allBits[index])
- {
- oneCount++;
- }
- }
- string zeros = new string('0', k);
- int zerosCount = 0;
- while(true)
- {
- index = allBits.IndexOf(zeros, index + 1);
- if(index == -1)
- {
- break;
- }
- if (allBits[index + k - 1] != allBits[index + k]
- && allBits[index - 1] != allBits[index])
- {
- zerosCount++;
- }
- }
- Console.WriteLine(zerosCount + oneCount);
- }
- }
- /*
- 3
- 4
- 5
- 6
- 14
- 143
- */
Advertisement
Add Comment
Please, Sign In to add comment