Friday, April 24, 2015

UVa 11933 - Splitting Numbers

#include <iostream>
using namespace std;

#define ull unsigned long long

int main() {
	while (true) {
		ull n;
		cin >> n;
		if (n == 0)
			break;

		ull current_bit = 1, sol_a = 0, sol_b = 0;
		bool turn_of_a = true;
		while (n) {
			if (n & 1) {
				if (turn_of_a)
					sol_a += current_bit;
				else
					sol_b |= current_bit;
				turn_of_a = !turn_of_a;
			}
			current_bit <<= 1;
			n >>= 1;
		}

		cout << sol_a << " " << sol_b << endl;
	}
	return 0;
}

No comments:

Post a Comment