UVA 10931 Parity Soution

Solve in C++:

#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,i,c=0;
  string a;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
            break;
        for(i=0; n>0; i++)
        {
            a[i]=n%2;
            n=n/2;
        }
        printf("The parity of ");
        for(i=i-1; i>=0; i--)
        {

            if(a[i]==1)
                c++;
            printf("%d",a[i]);
        }
        printf(" is %d (mod 2).\n",c);
        c=0;

    }

    return 0;
}

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.