-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigInteger.cpp
78 lines (75 loc) · 2.06 KB
/
BigInteger.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
struct BigInteger {
static const int BASE = 10000;
static const int WIDTH = 4;//s每一个单元保存4位数
vector<int> s;
BigInteger operator = (const string& str);
BigInteger operator = (int);
BigInteger operator = (long long);
BigInteger(long long num = 0) { *this = num; }
BigInteger operator + (int);
BigInteger operator - (const int);
BigInteger operator * (const int);
BigInteger operator / (const int);
BigInteger operator + (const BigInteger);
BigInteger operator - (const BigInteger);
BigInteger operator * (const BigInteger);
BigInteger operator / (const BigInteger);
BigInteger operator = (const string& str) {
s.clear();
int x, len = (str.length() - 1)/WIDTH + 1;
for(int i = 0; i < len; i++) {
int end = str.length() - i*WIDTH;
int start = max(0, end - WIDTH);
sscanf(str.substr(start, end-start).c_str(),"%d",&x);
s.push_back(x);
}
return *this;
}
BigInteger operator = (long long num) {
s.clear();
do {
s.push_back(num % BASE);
num/=BASE;
} while(num > 0);
return *this;
}
BigInteger operator = (int num){
s.clear();
do{
s.push_back(num % BASE);
num /= BASE;
}while(num > 0);
return *this;
}
BigInteger operator + (BigInteger num){
}
BigInteger operator + (int num) {
BigInteger Num = num;
return *this + Num;
}
};
ostream& operator << (ostream &out, const BigInteger& x){
out << x.s.back();
for(int i = x.s.size()-2; i >= 0; i--){
char buf[20];
sprintf(buf, "%08d", x.s[i]);
for(int j = 0; j < strlen(buf); j++) out << buf[j];
}
return out;
}
istream& operator >> (istream &in, BigInteger& x){
string s;
if(!(in >> s)) return in;
x = s;
return in;
}
int main(){
}