Page 10 of 10

### Re: 713 - Adding Reversed Numbers

Posted: Mon May 12, 2014 8:08 pm
i got accepted in both spoj and codechef but giving wrong answer in uva why is it so??
why? why??

#include<cstdio>
int main()
{
long long int t,a,b,p,reverse,reverse1,reverse2;
scanf("%lld",&t);
while(t--)
{
reverse=0;
reverse1=0;
reverse2=0;
scanf("%lld%lld",&a,&b);
while(a!=0)
{
reverse=reverse*10;
reverse=reverse+(a%10);
a/=10;
}
while(b!=0)
{
reverse1=reverse1*10;
reverse1=reverse1+(b%10);
b/=10;
}
p=reverse+reverse1;
while(p!=0)
{
reverse2=reverse2*10;
reverse2=reverse2+(p%10);
p/=10;
}
printf("%lld",reverse2);
printf("\n");
}
return 0;
}

### Re: 713 - Adding Reversed Numbers

Posted: Wed Aug 20, 2014 8:16 am
brianfry713 wrote:Try input:

Code: Select all

``````1
30 30``````
Output should be 60
My accepted program returns 6 instead of 60. Here are the steps below.

Code: Select all

``````Reverse ( Reverse(30) + Reverse(30) ) = Reverse (3 + 3)
= Reverse (6)
= 6
``````

### Re: 713 - Adding Reversed Numbers

Posted: Wed Aug 20, 2014 7:54 pm
v1n1t, your input is invalid. I also deleted my post with tailing zeros input. In the judge's input there are no test cases with trailing zeros. From the problem statement "Also note that the reversed number never has any trailing zeros."

### Re: 713 - Adding Reversed Numbers

Posted: Wed Aug 27, 2014 7:16 am
brianfry713 wrote:v1n1t, your input is invalid. I also deleted my post with tailing zeros input. In the judge's input there are no test cases with trailing zeros. From the problem statement "Also note that the reversed number never has any trailing zeros."
Thanks for bringing this to my attention, brianfry713. I've deleted my test cases.

### Re: 713 - Adding Reversed Numbers

Posted: Tue Sep 23, 2014 4:18 am
Deleted

### Re: 713 - Adding Reversed Numbers

Posted: Tue Sep 23, 2014 1:44 pm
I am not good in Java. I think you get RE because of Integer.parseInt. You use it for Biginteger. Change your code

Code: Select all

``````BigInteger a = new BigInteger(sb1.reverse().toString());

BigInteger b = new BigInteger(sb2.reverse().toString());

StringBuilder sb = new StringBuilder(num.toString()).reverse();

num = new BigInteger(sb.toString());

System.out.println(num);``````
Don't forget to remove your code after getting accepted.

### Re: 713 - Adding Reversed Numbers

Posted: Sun Nov 02, 2014 7:52 am
Thanks a lot....deleted

### Re: 713 - Adding Reversed Numbers

Posted: Mon Nov 03, 2014 8:33 am

Don't use Integer.parseInt for big numbers. Use Integer.parseInt for integers.

For this version of your code change following part

Code: Select all

``````s1 = new BigInteger("" + Integer.parseInt(ck1.reverse().toString()));
s2 = new BigInteger("" + Integer.parseInt(ck2.reverse().toString()));
``````
It must be

Code: Select all

``````s1 = new BigInteger(ck1.reverse().toString());
s2 = new BigInteger(ck2.reverse().toString());
``````
Also remove br.close().