// UVa 10931 - Parity
#include <iostream>
#include <stack>
using namespace std;
#define type long long unsigned int
string tobin(stack<int> & bin) {
string st = "";
while (!bin.empty()) {
st += bin.top();
bin.pop();
}
return st;
}
int main() {
type n;
cin >> n;
while (n) {
int parity = 0;
stack<int> bin;
type m = n;
while (m > 0) {
int bit = m & 1;
m >>= 1;
if (bit)
parity++;
bin.push(bit + '0');
}
cout << "The parity of " << tobin(bin) << " is " << parity << " (mod 2)." << endl;
cin >> n;
}
return 0;
}
No comments:
Post a Comment