Saturday, April 23, 2016

1182 - Parity

Problem linkhttp://www.lightoj.com/volume_showproblem.php?problem=1182

Solve :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    long long int t,n,j,k=1,cnt;

    scanf("%lld",&t);

    while(t--)
    {
        scanf("%lld",&n);
        cnt=0;
        while(n)
        {
            j=n%2;
            if(j==1) cnt++;
            n=n/2;
        }
        if(cnt%2==0) printf("Case %lld: even\n",k);
        else printf("Case %lld: odd\n",k);
        k++;
    }

}

No comments:

Post a Comment