Facebook
From A. Kadri Turker, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 107
  1. #include <iostream>
  2.  
  3. int main() {
  4.   int a;
  5.   int b;
  6.   std::cin >> a; // = 1 in the example
  7.   std::cin >> b; // = 2 in the example
  8.   a = a^b; // a is the XOR of a and b
  9.   b = a^b; // b is (a^b)^b = a^(b^b) = a^0 = a
  10.   a = a^b; // b's value is a at this point, so: a = a^b^a = b^(a^a) = b^0 = b
  11.   std::cout << a << std::endl;
  12.   std::cout << b << std::endl;
  13.  
  14.   return 0;
  15. }