SHARE
TWEET

5. Search in Bits

a guest Feb 4th, 2015 306 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. class Program
  10. {
  11.     static void Main()
  12.     {
  13.         Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  14.         string S = Console.ReadLine();
  15.         string SBin = Convert.ToString(int.Parse(S), 2).PadLeft(4, '0');
  16.  
  17.         int N = int.Parse(Console.ReadLine());
  18.  
  19.         int[] numbers = new int[N];
  20.  
  21.         for (int i = 0; i < N; i++)
  22.         {
  23.             numbers[i] = int.Parse(Console.ReadLine());
  24.         }
  25.  
  26.         int count = 0;
  27.  
  28.         for (int i = 0; i < numbers.Length; i++)
  29.         {
  30.             string numberBin = Convert.ToString(numbers[i], 2).PadLeft(32, '0');
  31.             string currentCheck = "";
  32.            
  33.             for (int j = 1; j <= 27; j++)
  34.             {
  35.                 for (int k = 3; k >= 0; k--)
  36.                 {
  37.                     currentCheck += numberBin[numberBin.Length - j - k].ToString();
  38.                 }
  39.                
  40.                 if (currentCheck == SBin)
  41.                 {
  42.                     count++;
  43.                 }
  44.  
  45.                 currentCheck = "";
  46.             }
  47.         }
  48.         Console.WriteLine(count);
  49.     }
  50. }
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
 
Top