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;
- class BinaryDigitsCount
- {
- static void Main(string[] args)
- {
- uint BInput = uint.Parse(Console.ReadLine());
- uint B = 0;
- uint N = uint.Parse(Console.ReadLine());
- uint currentNum;
- int counter;
- uint[] numbers = new uint[N];
- if (BInput == 0)
- {
- B = BInput + 1;
- }
- else
- {
- B = 1;
- }
- for (int i = 0; i < N; i++)
- {
- numbers[i] = uint.Parse(Console.ReadLine());
- }
- for (int i = 0; i < N; i++)
- {
- counter = 0;
- currentNum = numbers[i];
- if (BInput == 1)
- {
- while (currentNum != 0)
- {
- if ((currentNum & B) == 1)
- {
- counter++;
- }
- currentNum = currentNum >> 1;
- }
- }
- else
- {
- while (currentNum != 0)
- {
- if ((currentNum & B) != 1)
- {
- counter++;
- }
- currentNum = currentNum >> 1;
- }
- }
- Console.WriteLine(counter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement