Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class DancingBits
- {
- static void Main()
- {
- int k = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- int len = 0, sequence = 0, lastBit = 0;
- for (int i = 0; i < n; i++)
- {
- int nextNumber = int.Parse(Console.ReadLine());
- bool isOne = false;
- for (int g = 31; g >= 0; g--)
- {
- int bit = nextNumber >> g & 1;
- if(bit == 1)
- {
- isOne = true;
- }
- if(isOne)
- {
- if(lastBit == bit)// ако започваме нова редица не влиза тук
- {
- len++;
- }
- else
- {
- if(len == k)
- {
- sequence++;
- }
- len = 1;//ако сме намерили поредица, започваме нова
- }
- lastBit = bit;
- }
- }
- }
- if(len == k)//ако има поредица в края кажи!
- {
- sequence++;
- }
- Console.WriteLine(sequence);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment