Advertisement
Guest User

05.BitShifting

a guest
Apr 14th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System;
  2.  
  3. class BitShifting
  4. {
  5.     static void Main()
  6.     {
  7.         ulong input = ulong.Parse(Console.ReadLine());
  8.         int n = int.Parse(Console.ReadLine());
  9.         int count = 0;
  10.         ulong one = 1;
  11.         for (int i = 0; i < n; i++)
  12.         {
  13.             ulong num = ulong.Parse(Console.ReadLine());
  14.             input = (input | num) ^ num;
  15.         }
  16.        
  17.         while (input != 0)
  18.         {
  19.             ulong bit = input & one;
  20.             if(bit == 1)
  21.             {
  22.                 count++;
  23.             }
  24.             input >>= 1;
  25.         }
  26.         Console.WriteLine(count);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement