題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=21&page=show_problem&problem=1872
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #include <iostream> #include <bitset>
using namespace std;
int main(){ int i; while(cin >> i){ if(i == 0) break;
bitset<32> b(i); string str = b.to_string(); string ans = str.substr(str.find('1')); int parity = b.count();
cout << "The parity of " << ans << " is " << parity << " (mod 2).\n"; } }
|