-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber.cpp
51 lines (49 loc) · 882 Bytes
/
Number.cpp
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
50
51
#include <vector>
#include "Number.h"
N::N(unsigned int n){
unsigned int o=n;
while(o>0){
v.insert(begin(v),o%10);
o/=10;
}
}
N::N(const N &i){
v=i.v;
_symbol=i._symbol;
}
N::N(const std::string &s){
int k=s.length()-1;
for(int i=0;i<=k;i++){
v.push_back(s[i]-'0');
}
}
N N::operator+(const N &i){
N n=*this;
int j=0;
int l=i.v.size()-1;
int k=n.v.size()-1;
if(k<l){
for(;k<l;k++){
n.v.insert(begin(n.v),0);
}
}
int add=0;
for(l;l>=0;l--){
add=(n.v[k]+i.v[l]+j)%10;
j=((n.v[k]+i.v[l]+j)-add)/10;
n.v[k]=add;
k--;
}
if(j>0){
n.v.insert(begin(n.v),j);
}
return n;
}
void N::readv(){
auto i = begin(v);
auto e = end(v)-1;
for(;i<=e;i++){
std::cout<<*(i);
}
std::cout<<std::endl;
}