@RAWBERRY:
Re:
The r_itSum and r_itSmall are pointing to rShortStr and numStrSum. |
Those are actually iterators, which are similar to pointers. The ones in use are "reverse" iterators. They move through the strings backwards.
Re:
And what is the point of subtracting the '0'? |
I'm manipulating character values here not integer values. The character '0' has an ascii value = 48 not 0. Suppose I want to get '3' + '2' = '5'. Adding the ascii values wouldn't work right.
I would get '3' + '2' = 51 + 50 = 101 = acii value of 'e'.
I'm subtracting '0' to get an offset to the character sought:
'3' + ( '2' - '0' ) = 51 + ( 50 - 48 ) = 51 + 2 = 53 = ascii value of '5'
Does that make sense?
NOTE: The program I gave is ready for use. Just change the values for numStr1 and numStr2 to what you want (eg. some 50 digit #'s). Better yet, modify the program so that it reads in strings input by the user for numStr1 and numStr2. This way the program doesn't have to be rebuilt every time you change the values.
ie. Replace:
1 2
|
string numStr1 = "662357";
string numStr2 = "56487";// sum should = 718844
|
With:
1 2 3 4
|
string numStr1;
string numStr2;
cout << "Enter 1st number: "; cin >> numStr1;
cout << "Enter 2nd number: "; cin >> numStr2;
|
Also:
Browni3141 wrote: |
---|
Using a bignum for projecteuler is overkill. Almost all of the problems are doable with 64-bit integers. Most of the one's that can't can be done with arrays/vectors and the arithmetic algorithms you learned in elementary school. |
True. Use of a full on general purpose bignum library may be overkill. My method above just implements the grade school method for adding two numbers on paper.
Did you get problem #16? (find the sum of the digits of 2^1000)
http://projecteuler.net/index.php?section=problems&id=16
I recall you discussing that one previously. Did you solve it using 64-bit integers?