Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- namespace BinaryDigitsCount
- {
- class BinaryDigitsCount
- {
- static void Main(string[] args)
- {
- int b = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- int counter = 0;
- long[] arr = new long[n];
- for (int i = 0; i < n; i++)
- {
- counter = 0;
- long m = long.Parse(Console.ReadLine());
- string mBynari = Convert.ToString(m,2);
- for (int col = 0; col < mBynari.Length; col++)
- {
- if (b == 1)
- {
- if (mBynari[col] == '1')
- {
- counter++;
- }
- }
- else if (b == 0)
- {
- if (mBynari[col] == '0')
- {
- counter++;
- }
- }
- }
- arr[i] = counter;
- }
- for (int i = 0; i < arr.Length; i++)
- {
- Console.WriteLine(arr[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement