UVA-575 Skew Binary

import static java.lang.Math.pow;
import java.util.*;
import java.math.*;
public class Main {

  
    public static void main(String[] args) {
        BigInteger n,sum,r,z,k;
        z=BigInteger.valueOf(2);
        k=BigInteger.valueOf(1);
        int i;
        double p=10;
        Scanner input=new Scanner(System.in);
    
        while(input.hasNext())
        {
            n=input.nextBigInteger();
            if(n.compareTo(BigInteger.valueOf(0))==0)
            {
                break;
            }
            i=1;
            sum=BigInteger.ZERO;
            while(n.compareTo(BigInteger.valueOf(0))!=0)
            {
              r=n.mod(BigInteger.TEN);
              sum=sum.add(r.multiply(z.pow(i).subtract(k)));
              n=n.divide(BigInteger.valueOf(10));
              i++;
            }
            System.out.println(sum);
           
           
        }
    }
   
}

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