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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.