Advertisement
Guest User

FindBits

a guest
May 20th, 2015
216
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 FindBits
  4. {
  5.     static void Main()
  6.     {
  7.         int s = int.Parse(Console.ReadLine());
  8.         int n = int.Parse(Console.ReadLine());
  9.         int counter = 0;
  10.  
  11.         for (int i = 0; i < n; i++)
  12.         {
  13.             int input = int.Parse(Console.ReadLine());
  14.  
  15.             for (int j = 0; j < 24; j++)
  16.             {
  17.                 int mask = 31 << j;
  18.                 int maskAndInput = (input & mask) >> j;
  19.                 if (maskAndInput == (s & 31))
  20.                 {
  21.                     counter++;
  22.                 }
  23.             }
  24.         }
  25.         Console.WriteLine(counter);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement