Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Trello, Facil, Suma de numeros grandes
- #include <iostream> /// AlenAntonelli
- using namespace std;
- bool validar (string x);
- string voltear (string x);
- string redimencionar (string chica, string grande);
- int main ()
- {
- unsigned int aux=0;
- bool ban;
- string a, b, c;
- cout<<"Ingrese el primer sumando:";
- cin>>a;
- cout<<"Ingrese el segundo sumando:";
- cin>>b;
- a=redimencionar(a,b);
- b=redimencionar(b,a);
- c=redimencionar(c,a);
- for (int i=c.size()-1; i>=0; i--)
- {
- c[i]=(a[i]+b[i]-96+aux)%10+48;
- aux=(a[i]+b[i]-96+aux)/10;
- }
- if (aux!=0)
- {
- c=voltear(c);
- c.push_back(49);
- c=voltear(c);
- }
- cout<<"La suma es:"<<c;
- return 0;
- }
- string voltear (string x)
- {
- for (int i=0; i<(x.size()/2); i++)
- swap(x[i],x[x.size()-1-i]);
- return x;
- }
- string redimencionar (string chica, string grande)
- {
- if (chica.size()<grande.size())
- {
- chica=voltear(chica);
- int sta = grande.size() - chica.size();
- for(int i=0; i<sta; i++)
- chica.push_back(48);
- chica=voltear(chica);
- }
- return chica;
- }
- /**bool validar (string x)
- {
- bool ban=true, ban2=true;
- if (x.size()>199)
- {
- ban=false;
- cout<<"la cadena numerica ingresada excede los 200 caracteres"<<endl;
- }
- for (int i=0; ban2==true && i<x.size(); i++)
- 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' )
- {
- ban =false;
- ban2=false;
- }
- if (ban2==false)
- cout<<"Uno de los caracteres ingresado no es numerico"<<endl;
- if (ban==false || ban2==false)
- return false;
- else return true;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment