UVA 10019 Funny Encryption Method







#include <bits/stdc++.h>
using namespace std;
int binary(int n)
{
    int a[1000],i=0,j,c=0;
    while(n>0)
    {
        a[i]=n%2;
        i++;
        n=n/2;
    }
    for(j=i-1;j>=0;j--)
    {
        if(a[j]==1)
        {
            c++;
        }
    }
    return c;
}

int main()
{
    int t,n,sum,k,l,m,r,tmp,en;
    //freopen("10019.txt","r",stdin);
    //freopen("10019out.txt","w",stdout);
    cin>>t;
    for(k=1;k<=t;k++)
    {
        cin>>n;
        tmp=n;
        l=binary(n);
        sum=0;
        while(tmp>0)
        {
            r=tmp%10;
            sum=sum+binary(r);
            tmp=tmp/10;
        }
        printf("%d %d\n",l,sum);
    }
    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment