Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string suma(string nA, double B) {
- string nB=std::to_string(B);
- string respuesta("");
- string tmp("");
- int c(0);
- int posA = nA.length()-1;
- int posB = nB.length()-1;
- int resto (0);
- int digA, digB;
- while(posA>=0 || posB>=0) {
- digA = (posA>=0) ? nA[posA]-'0': 0;
- digB = (posB>=0) ? nB[posB]-'0': 0;
- c= digA+digB+resto;
- if(c>=10) { resto=1; c=c-10;} else {resto=0;}
- tmp+=c+'0';
- posA--;
- posB--;
- }
- if(resto>0) tmp+=resto+'0';
- for (int i=tmp.length()-1 ;(i>=0 && tmp[i]!='$' ) ;i--){respuesta+=tmp[i];}
- return respuesta;
- }
- int main()
- {
- double array[]={22000000001,1000000002,1000000003,1000000004,1000000005};
- string resultado(std::to_string(array[0]));
- for (size_t i=(sizeof (array)/sizeof(array[0]));i>0;i--){
- resultado=suma(resultado,array[i]);
- }
- cout <<resultado<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement