#include <iostream>
using namespace std;
unsigned power10(unsigned y) {
unsigned result = 1;
while(y--)
result = (result << 3) + (result << 1);
return result;
}
int sign(int a) {
if(a < 0)
return -1;
else
return 1;
}
void swap(int& a, int& b, unsigned k, unsigned l) {
const int multiply_a = power10(k);
const int multiply_b = power10(l);
const int digit_a = sign(a) * (a / multiply_a) % 10;
const int digit_b = sign(b) * (b / multiply_b) % 10;
const int add_a = multiply_a * digit_b - multiply_a * digit_a;
const int add_b = multiply_b * digit_a - multiply_b * digit_b;
a = a + sign(a)*add_a;
b = b + sign(b)*add_b;
}
int main() {
{
int a = 12345;
int b = 98765;
cout << a << ", " << b << " : ";
swap(a, b, 1, 4);
cout << a << ", " << b << endl;
}
{
int a = -12345;
int b = 98765;
cout << a << ", " << b << " : ";
swap(a, b, 1, 4);
cout << a << ", " << b << endl;
}
{
int a = -12345;
int b = -98765;
cout << a << ", " << b << " : ";
swap(a, b, 1, 4);
cout << a << ", " << b << endl;
}
return 0;
}