#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

class numerote {
    private:
        char* dig;
        int   lon;
    public:
        numerote(string n= "");
        numerote(int n);
       ~numerote(void);
        int   operator () (int k) const;
        char& operator [] (int k);
        int longitud(void) const  { return lon; };
        numerote& operator = (const numerote& u);
        void normal(void);
};

numerote operator + (const numerote& a, const numerote& b)
{
   int n= max(a.longitud(), b.longitud());
   numerote s(n+1);
   int c= 0;
   for (int k=0; k<n; k++)
      {
       int t= a(k) + b(k) + c;
       s[k]= t%10;
       c= t/10;
      }
   s[n]= c;
   s.normal();
   return s;
}

numerote operator * (const numerote& a, const numerote& b)
{
   int n= a.longitud() + b.longitud();
   numerote p(n);
   int c= 0;
   for (int k=0; k<n; k++)
      {
       int s= c;
       for (int i=0; i<=k; i++)
          s+= a(i) * b(k-i);
       p[k]= s%10;
       c= s/10;
      }
   p.normal();
   return p;
}


numerote::numerote(int n)
{
   lon= n;
   dig= new char [lon];
   for (int k=0; k<lon; k++)
     dig[k]= 0;
}


numerote::numerote(string n)
{
    if (n=="")
        n= "0";
    lon= n.length();
    dig= new char[lon];
    for (int k=0, r=lon-1; k<lon; k++, r--)
      dig[k]= n[r] - '0';  
}

numerote::~numerote(void)
{
   delete [] dig;
}

numerote& numerote::operator = (const numerote& u)
{
   lon= u.lon;
   dig= new char [lon];
   for (int k=0; k<lon; k++)
     dig[k]= u.dig[k];
   return *this;
}


int numerote::operator () (int k) const
{
   return k < lon ? dig[k] : 0;
}

char& numerote::operator [] (int k)
{
   return dig[k];
}

void numerote::normal(void)
{
   int n= lon-1;
   while (n>0 && dig[n]==0)
       n--;
   lon= n+1; 
}

ostream& operator << (ostream& os, const numerote& u)
{
    int n= u.longitud()-1;
    for (int k=n; k>=0; k--)
      os << u(k);
    return os;
}


int main(int nargs, char* args[])
{
    string a, b;
    cout << "dar un numerote\n";
    cin >> a;

    cout << "dar un numerote\n";
    cin >> b;

    numerote x(a);
    numerote y(b);

    cout << "x= "<< x << endl;
    cout << "y= "<< y << endl;
    cout << "x+y= "<< x+y << endl;
    cout << "x*y= "<< x*y << endl;

    return EXIT_SUCCESS;
}


