Advertisement
EvlogiHr

Untitled

Dec 27th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Globalization;
  4.  
  5. class P4DansingBits
  6. {
  7. static void Main()
  8. {
  9. int k = int.Parse(Console.ReadLine());
  10. int n = int.Parse(Console.ReadLine());
  11. int[] arr = new int[n];
  12. string binary = null;
  13. for (int i = 0; i < n; i++)
  14. {
  15. arr[i] = int.Parse(Console.ReadLine());
  16. binary += Convert.ToString(arr[i], 2);
  17. }
  18. int strLength = binary.Length;
  19. BigInteger bigNum = 0;
  20. foreach (char c in binary)
  21. {
  22. bigNum <<= 1;
  23. bigNum += Convert.ToInt32(c.ToString());
  24. }
  25. int danceingNumbersCount = 0;
  26. int bit = 0;
  27. while (bit < strLength)
  28. {
  29. int localCount = 1;
  30. while (bit < strLength)
  31. {
  32. if (((bigNum >> bit) & 1) == ((bigNum >> (bit + 1)) & 1))
  33. {
  34. localCount++;
  35. }
  36. else
  37. {
  38. bit++;
  39. break;
  40. }
  41. bit++;
  42. }
  43. if (localCount == k)
  44. {
  45. danceingNumbersCount++;
  46. }
  47. }
  48. Console.WriteLine(danceingNumbersCount);
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement