language: C++ 4.7.2 (gcc-4.7.2)
date: 786 days 23 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
 
struct char2digit
{
   char operator()(char c) { return c - '0'; }
};
 
class IntegerNumber
{
   std::vector<char> m_digits;
   public:
          IntegerNumber()
          {
             m_digits.push_back(0);
          }
          IntegerNumber(const std::string &number)
          {
               std::transform(number.begin(),number.end(),
                              std::back_inserter(m_digits), char2digit());
          }
          IntegerNumber operator+(const IntegerNumber & number)
          {
               IntegerNumber result(number);
               
               return result;      
          }
          friend std::ostream & operator<<(std::ostream &out, const IntegerNumber &number);
};
 
std::ostream & operator<<(std::ostream &out, const IntegerNumber &number)
{
   std::copy(number.m_digits.begin(), number.m_digits.end(),std::ostream_iterator<int>(out));
   return out;
}
 
int main() 
{
        IntegerNumber A;
        IntegerNumber B("12345678954688709764347890");
        std::cout << A << std::endl;
        std::cout << B << std::endl;
        A = A + B;
        std::cout << A << std::endl;
        return 0;
}