fork download
  1. #include <stdio.h>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. struct Hamming {
  7. int x, y;
  8.  
  9. Hamming(int x, int y) :
  10. x(x),
  11. y(y)
  12. {}
  13.  
  14. static Hamming read() {
  15. int x, y;
  16. cin >> x >> y;
  17. return Hamming{x, y};
  18. }
  19.  
  20. int distance(int x, int y) {
  21. int number = x ^ y;
  22. int counter = 0;
  23.  
  24. while (number > 0) {
  25. counter += (number & 1);
  26. // counter += number % 2
  27. number >>= 1;
  28. // number /= 2;
  29. }
  30. return counter;
  31. }
  32. };
  33.  
  34. int main() {
  35. #ifdef LOCAL
  36. freopen("input.txt", "r", stdin);
  37. #endif
  38. Hamming var = Hamming::read();
  39.  
  40. cout << var.distance(var.x, var.y) << "\n";
  41.  
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
0