SHARE
TWEET

BinaryDigitsCount

Teodor92 Nov 28th, 2012 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class BinaryDigitsCount
  4. {
  5.     static void Main()
  6.     {
  7.         byte digit = byte.Parse(Console.ReadLine());
  8.         short n = short.Parse(Console.ReadLine());
  9.         for (int i = 0; i < n; i++)
  10.         {
  11.             long number = long.Parse(Console.ReadLine());
  12.             int digitCounter = 0;
  13.             while(true)
  14.             {
  15.                 if (number == 0)
  16.                 {
  17.                     break;
  18.                 }
  19.                 if( number % 2 == digit)
  20.                 {
  21.                     digitCounter++;
  22.                 }
  23.                 number = number / 2;
  24.             }
  25.             Console.WriteLine(digitCounter);
  26.         }
  27.  
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top