Page 9 of 10
Re: 713 - Adding Reversed Numbers
Posted: Sun Nov 24, 2013 5:38 am
by mentalist_mbstu
i don't understand could u tell in details
Re: 713 - Adding Reversed Numbers
Posted: Mon Nov 25, 2013 9:11 am
by mentalist_mbstu
brianfry713 wrote:On my machine your code doesn't match the sample input. It is printing some extra characters on the third line.
i don't understand could u tell in details
Re: 713 - Adding Reversed Numbers
Posted: Tue Nov 26, 2013 1:06 am
by brianfry713
Re: 713 - Adding Reversed Numbers
Posted: Wed Nov 27, 2013 12:05 pm
by mentalist_mbstu
bt when i input
2
1 999999
999999 999999
output
1
8999991
bt when i input
2
999999 999999
1 999999
output
8999991
99991
i could not catch it
Re: 713 - Adding Reversed Numbers
Posted: Wed Dec 04, 2013 2:09 am
by brianfry713
You're reading past the end of a string.
Re: 713 - Adding Reversed Numbers
Posted: Fri Dec 06, 2013 11:11 am
by mentalist_mbstu
i don't understand what u want to say
brianfry713 wrote:You're reading past the end of a string.
Re: 713 - Adding Reversed Numbers
Posted: Fri Dec 06, 2013 9:34 pm
by brianfry713
A string is terminated with a null character. Your code continues to read beyond that into uninitialized data.
Re: 713 - Adding Reversed Numbers
Posted: Sat Dec 07, 2013 2:49 pm
by mentalist_mbstu
i am new in string..so would u like to specify which line i make mistake?
brianfry713 wrote:A string is terminated with a null character. Your code continues to read beyond that into uninitialized data.
Re: 713 - Adding Reversed Numbers
Posted: Sun Feb 09, 2014 12:32 pm
by MNT.95
My code is AC in SPOJ and POJ, but in UVA it is WA??
Why is that heppens to the same code ??
Re: 713 - Adding Reversed Numbers
Posted: Sun Feb 09, 2014 12:45 pm
by MNT.95
My code
Code: Select all
#include<stdio.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long x,rev_x=0,y,rev_y=0,sum,rev_sum=0;
scanf("%d %d",&x,&y);
while(x>0)
{
rev_x *= 10;
rev_x += x%10;
x=x/10;
}
while(y>0)
{
rev_y *= 10;
rev_y += y%10;
y=y/10;
}
sum=rev_x+rev_y;
while(sum>0)
{
rev_sum *= 10;
rev_sum += sum%10;
sum=sum/10;
}
printf("%d\n",rev_sum);
}
return 0;
}
Re: 713 - Adding Reversed Numbers
Posted: Mon Feb 10, 2014 11:17 pm
by brianfry713
use scanf("%lld") for a long long
Re: 713 - Adding Reversed Numbers
Posted: Tue Mar 04, 2014 9:40 am
by uDebug
brianfry713,
Thanks very much for the host of test cases.
Update: Deleted own test cases per post by brianfry713.
Re: 713 - Adding Reversed Numbers
Posted: Tue Mar 04, 2014 9:43 am
by uDebug
Replying to follow the thread.
Re: 713 - Adding Reversed Numbers
Posted: Sun Mar 16, 2014 12:12 am
by try_tired
Why I got wrong ans: here.......... pls help.
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args)throws IOException {
try{
String s,ss,sum1;
StringBuffer s1,s11,sum2;
BigInteger sum;
long l1,l2,lf;
int n,i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(i = 1;i <= n;i++)
{
s = sc.next();
ss = sc.next();
s1 = new StringBuffer(s);
s1 = s1.reverse();
s = s1.toString();
l1 = Long.valueOf(s);
s11 = new StringBuffer(ss);
s11 = s11.reverse();
ss = s11.toString();
l2 = Long.valueOf(ss);
sum = BigInteger.valueOf(l1+l2);
sum1 = sum.toString();
sum2 = new StringBuffer(sum1);
sum2 = sum2.reverse();
sum1 = sum2.toString();
lf = Long.valueOf(sum1);
System.out.println(lf);
}
}catch(Exception e){
System.out.print("Error");
}
}
}
Re: 713 - Adding Reversed Numbers
Posted: Sun Mar 16, 2014 8:14 am
by uDebug
try_tired wrote:Why I got wrong ans: here.......... pls help.

First, consider using the code tags to share your code to make it more readable. Think about it: Would you spend even a moment looking at what you posted above as an objective reviewer?
Next, try searching the forums more extensively before you post. Here's a much more detailed thread with test cases and discussion.
http://acm.uva.es/board/viewtopic.php?f ... &hilit=713
Test your code with test cases given there.