AlenAntonelli

Suma_de_numeros_grandes_Alen

May 12th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. ///Trello, Facil, Suma de numeros grandes
  2. #include <iostream> /// AlenAntonelli
  3. using namespace std;
  4. bool validar (string x);
  5. string voltear (string x);
  6. string redimencionar (string chica, string grande);
  7. int main ()
  8. {
  9.     unsigned int aux=0;
  10.     bool ban;
  11.     string a, b, c;
  12.     cout<<"Ingrese el primer sumando:";
  13.     cin>>a;
  14.     cout<<"Ingrese el segundo sumando:";
  15.     cin>>b;
  16.     a=redimencionar(a,b);
  17.     b=redimencionar(b,a);
  18.     c=redimencionar(c,a);
  19.     for (int i=c.size()-1; i>=0; i--)
  20.     {
  21.         c[i]=(a[i]+b[i]-96+aux)%10+48;
  22.         aux=(a[i]+b[i]-96+aux)/10;
  23.     }
  24.     if (aux!=0)
  25.     {
  26.         c=voltear(c);
  27.         c.push_back(49);
  28.         c=voltear(c);
  29.     }
  30.     cout<<"La suma es:"<<c;
  31.     return 0;
  32. }
  33. string voltear (string x)
  34. {
  35.     for (int i=0; i<(x.size()/2); i++)
  36.         swap(x[i],x[x.size()-1-i]);
  37.     return x;
  38. }
  39. string redimencionar (string chica, string grande)
  40. {
  41.     if (chica.size()<grande.size())
  42.     {
  43.         chica=voltear(chica);
  44.         int sta = grande.size() - chica.size();
  45.         for(int i=0; i<sta; i++)
  46.             chica.push_back(48);
  47.         chica=voltear(chica);
  48.     }
  49.     return chica;
  50. }
  51. /**bool validar (string x)
  52. {
  53.     bool ban=true, ban2=true;
  54.     if (x.size()>199)
  55.     {
  56.         ban=false;
  57.         cout<<"la cadena numerica ingresada excede los 200 caracteres"<<endl;
  58.     }
  59.     for (int i=0; ban2==true && i<x.size(); i++)
  60.         if ( x[i]!='0' && x[i]!='1' && x[i]!='2' && x[i]!='3' && x[i]!='4' && x[i]!='5' && x[i]!='6' && x[i]!='7' && x[i]!='8' && x[i]!='9' )
  61.         {
  62.             ban =false;
  63.             ban2=false;
  64.         }
  65.     if (ban2==false)
  66.         cout<<"Uno de los caracteres ingresado no es numerico"<<endl;
  67.  
  68.     if (ban==false || ban2==false)
  69.         return false;
  70.  
  71.     else return true;
  72. }*/
Advertisement
Add Comment
Please, Sign In to add comment