| CosminNTG (180) | |||
|
Hello everybody! I have a major problem about some lists. That's my code:
I want to create a program that add two big numbers (with 1 milion digits). Well, I want to to that using lists from STL. I want to read the numbers as char arrays and then to convert the char - arrays into integers, and then to store them into those two lists. I know that atoi() function may help me but I don't really manage how to put every digit of that number in a location of a list. atoi() doesn't work if I want to convert only a character (for instance atoi(x[i]), it works only for the entire string. Also I tried with assign(atoi(x)) method but it must have two parameters and it doesn't help me very much. Please excuse my english, I am in a hurry and I hope that one of you might help me. Thank you respectfully. | |||
|
|
|||
| vlad from moscow (3112) | |||
| |||
|
Last edited on
|
|||
| CosminNTG (180) | |
|
Wow! Can you explain a bit what does that code? I try to understand those functions: transform and accumulate but I don't manage. Thank you respectfully. | |
|
|
|
| vlad from moscow (3112) | |||||
The first standard algorithm does the following
The second standard algorithm generates the number from elements of the list
| |||||
|
Last edited on
|
|||||
| vlad from moscow (3112) | |
| It demonstrates that in C++ any task can be done in different ways.:) | |
|
|
|
| Catfish2 (666) | |
|
C++11 lambda functions + algorithms! http://en.cppreference.com/w/cpp/algorithm/transform http://en.cppreference.com/w/cpp/algorithm/accumulate http://en.cppreference.com/w/cpp/language/lambda @ Cosmin: if Vlad's first examples don't compile for you, use the "translations" that he gave. (Otherwise, get a newer compiler that has good support for C++11.) | |
|
|
|
| CosminNTG (180) | |
|
Allright guys, thank you very much! | |
|
|
|
| Incis B (85) | |
|
C++11 lambda functions + algorithms! Tnx CatFish2 ! | |
|
|
|