![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
I have to add to big numbers. Ex:
"12345678998765443" + "1234656436756774233" I know i have to do it with string. The way i'm thinking, I'll transform them in integer... then add them like you would on a piece of paper then the result transform it again in strin and print it! String --> Integer Intger-->String ........ HowTO. 10x
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
int i = Integer.parseInt(str) Then I'm 99.9% sure it's str = valueOf(i);
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Those numbers appear to be a little bit too large to simply store in an integer, you need to get into 64bit mathematical operations if you actually want to do that.
I have seen this problem at a lot of programming competitions, the way to go about solving it is to write a function which performs mathematical operations on non-defined precision words by doing the operations on strings. In other words you test the character of each string and use that to generate the values of a new string which would represent your sum.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#4 |
|
Professional Programmer
|
Got it in the end.
Thanks for the help.
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|