## A plus B... again

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

Point Value: 15
Time Limit: 3.00s
Memory Limit: 16M

Problem Types: [Show]

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

<
1
2
>

• (4/2)
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.

• (7/1)
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())));     } }``

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

• (1/1)

• (1/1)
yes, otherwise the problem would be trivial.

• (1/1)
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

• (6/2)
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.

• (0/1)
The same as the title

• (0/1)
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.

• (1/1)
Are A and B on the same line separated by a space or two separate lines?

• (0/1)
Separate lines.

• (0/1)
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

• (1/1)
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?

• (1/1)
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

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

• (2/1)
You have the correct number of digits...they just seem to pretty much all be wrong >.<

• (1/1)
Ah.

• (2/2)
Thanks, that helped me very much!! :):)

• (0/1)
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?

• (0/1)
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.

• (0/1)
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.

• (0/1)

• (0/1)
Are you sure it's 26?

• (0/1)
I looked through your submission and it appears you had runtime error 216.
This indicates a general protection fault, probably caused by going out of bounds in memory.

• (1/1)
I still seem to be getting an error. I think its because I am not reading the input properly.

Any cryptic clues?? :P

• (0/1)
There are a lot of errors in your program - I think you need to learn a bit more about C++ before plugging in stuff from tutorials. (sizeof doesn't do what you think it does)

Why are you using char arrays? Just use strings.

• (1/1)
ok I am now using strlen(variable); but it doesn't work on int arrays. I don't see how I can I get their lengths.

And I am even on the right track??

• (0/2)
Hanson is correct; you should use strings. (This doesn't work in pascal because pascal strings are only 255 chars.)

If you use strings, just use s.length(), where s is a string.

• (0/2)
But thats not the problem. I am reading in fine for sure but the thing is my solution requires to have a int array of a certain size and use that to get the answer but I don't know how to find the size of the array for the loop to go upto.

Take a look at my solution. I tried to fix the problem, it still isn't working. :(

• (0/1)
strlen(variable)?

say I have the following:

string str;

the length of this string is str.length().

so i can do this:

for (i=0;i<str.length();i++)
cout<<str[i];

which would print the characters of the string.

• (1/2)
Yes, I know. But, it doesn't seem work if I want to find the length of an int array.

• (0/2)
KEep a running size count, which is easy to do, or use a vector, in which case you can indeed do:

int vector_size = v.size();

and that returns the number of elements in the vector.

however, vectors are a bit more advanced to use, so as Hanson suggested, become more proficient in C++.

• (0/2)