Uva 713 - Adding Reversed Numbers

/*     Uva 713 - Adding Reversed Numbers
 *    Verdict : Accepted
 *    Time : 0.159
 *    Problem Link : https://uva.onlinejudge.org/external/7/713.pdf
 **/
import java.util.*;
import java.math.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner in = new Scanner (System.in);
        int t,tc,n=10;
        tc = in.nextInt();
       
        for (t=1;t<=tc;t++)
        {
            BigInteger a,b,x,y,s1=BigInteger.valueOf(0),s2=BigInteger.valueOf(0),p=BigInteger.valueOf(10),s,r=BigInteger.valueOf(0),m;
            x=in.nextBigInteger(); y = in.nextBigInteger();
            a=x;b=x;
           
            while (a!=BigInteger.valueOf(0))
            {
                a = a.mod(p);
                s1 = a.add(s1.multiply(p));
                b = b.divide(p);
                a=b;
            }
           
            //System.out.print(s1);
           
            a=y;b=y;
           
            while (a!=BigInteger.valueOf(0))
            {
                a = a.mod(p);
                s2 = a.add(s2.multiply(p));
                b = b.divide(p);
                a=b;
            }
           
            s = s1.add(s2);
            //System.out.print(s);
            a = s ; b = s;
           
            while (a!=BigInteger.valueOf(0))
            {
                a=a.mod(p);
                r = a.add(r.multiply(p));
                b = b.divide(p);
                if (r == BigInteger.valueOf(0))
                {
                    r = BigInteger.valueOf(0);
                }
               
                a = b;
            }
           
            System.out.println(r);
        }
    }
}

Comments

Popular posts from this blog

Uva 10650 - Determinate Prime

SPOJ-CMG - Collecting Mango

LeetCode Palindrome Number