A plus B... again

Given two integers A and B (of no more than 100000 digits each), find their exact sum.

All Submissions
Best Solutions


Point Value: 15
Time Limit: 3.00s
Memory Limit: 16M
Added: Oct 24, 2008

Problem Types: [Show]

Languages Allowed:
C++03, PAS, C, ASM, C#, C++11

Comments (Search)

<
1
2
3
>

what is the point of this problem?
isnt it just like the first one?

64 bit integers cannot hold numbers of 100000 digits (i.e., of size 10^100000)


It's not like it makes it any easier, we still have to use string manipulation because java variables can't store such big integers.

Java has a built-in BigInteger class. A sample Java solution for this problem is as follows:

import java.util.Scanner; 
import java.math.BigInteger;

public class aplusb2 {
public static void main(String[] foo) {
Scanner in = new Scanner(System.in);
System.out.println((new BigInteger(in.next())).add(new BigInteger(in.next())));
}
}

What's the difference between
public static void main(String[] args)
and
public static void main(String[] foo)?


yes, otherwise the problem would be trivial.

The program is not working!
Is there a catch? I have used the same program as the
first A + B.
For Some reason it no work!
Its very Simple!


_________________

var 
a,b:integer;
begin
readln (a);
readln (b);
writeln (a+b);
end.



nothing to see here whistle.gif

http://wiki.freepascal.org/Integer

Integers only have a capacity of -231 to 231 -1 which is 10 digits long while this problem has input that may be up to 100 000 digits each. So you'll have to find another method to solve this. For future reference don't post your code in the comments and please refer to this before posting a question.

http://wcipeg.com/comments/view#comment3719

The same as the title

It's exactly as the problem states: add two numbers together, each of which may be up to 100 000 digits long.

Note that python is disallowed because it has bignums.

Are A and B on the same line separated by a space or two separate lines?

Separate lines.

This took a while to get. Can anyone help shorten my code and possibly how to make it so that my code doesn't have those extra if statements at the end? Thnx

I just wanted to make sure that the only thing that I need to add in my program is adding one negative and one positive numbers right?

Assuming you have correctly implemented the sum of two positive numbers and the sum of two negative numbers, logically, yes, all that remains is handling the cases in which one is positive and one is negative.

Make sure it's done correctly though tongue.gif

What is the correct answer for 6th and 8th test case?? I just want to compare it to what I am outputting....

You have the correct number of digits...they just seem to pretty much all be wrong >.<


Thanks, that helped me very much!! :):)

After changing the way i read in the file (numbers),i found that the judge accepted the output that my program outputted, but when tested on my computer, i found that the program outputs an extra zero for the sum.
Why is the judge accepting a wrong answer (or is the version of pascal that i am using just messed up)? Also, is this basically the same problem i had before?

I'm sorry, what cases are you talking about? (I cannot see the output of your program on the judge if it is judged as correct; only when there is a problem can I see it.)

I do notice that for several cases you printed '0' instead of a minus sign.

At my computer, the program outputs an extra zero for all sums of two positive integers (making it incorrect), though it is accepted here on the judge.