AC代码(就是把一个数转化为二进制然后看他有几个1)
Select Code
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
long long n;
int a[100], i;
while(cin>>n&&n!=0)
{
long long int h = 0, sm = 0;
while(n)
{
a[h++] = n%2;
if(n%2==1)
sm++;
n = n/2;
}
printf("The parity of ");
for(i = h-1;i>=0;i--)
{
printf("%d",a[i]);
}
printf(" is %lld (mod 2).\n",sm);
}
return 0;
}