fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string binary(int n)
  5. {
  6. string s = "" ;
  7. // Size of an integer is assumed to be 32 bits
  8. for (int i = 31; i >= 0; i--) {
  9. int k = n >> i;
  10. if (k & 1)
  11. s = s.append("1") ;
  12. else
  13. s = s.append("0") ;
  14. }
  15. return s ;
  16. }
  17.  
  18. int main() {
  19.  
  20. int n,m,k ;
  21. cin >> n >> m >> k ;
  22. int a[m+1] ;
  23. for (int i = 0; i <= m; i++)
  24. cin >> a[i] ;
  25.  
  26. int l = 0 ;
  27. string q = binary(a[m]) ;
  28.  
  29. for (int i = 0; i < m; i++)
  30. {
  31. string z = binary (a[i]) ;
  32. int c = 0 ;
  33. for (int j = 0; j < n; j++)
  34. {
  35. if (q[j]!=z[j])
  36. {
  37. c++ ;
  38. }
  39. }
  40.  
  41. if (c <= k)
  42. l++ ;
  43. }
  44.  
  45. cout << l ;
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 15240KB
stdin
7 3 1
8
5
111
17
stdout
3