包括高精度间的加、减、乘,及高精度除低精度,正数高精度模低精度
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
struct BigInt {
int num[1000];
int len;
bool symbol;
BigInt() {
fill(num, num + 1000, 0);
len = 0;
symbol = true;
}
void set(string str) {
int tmp = 0;
int weight = 1;
if (str[0] == '-') {
symbol = false;
str = str.substr(1);
}
for (int i = str.size() - 1; i >= 0; i--) {
tmp += (str[i] - '0') * weight;
weight *= 10;
if (weight == 10000 || i == 0) {
num[len] = tmp;
tmp = 0;
weight = 1;
len++;
}
}
}
void output() {
if (!symbol && !(len == 1 && num[0] == 0))
cout << '-';
cout << num[len - 1];
for (int i = len - 2; i >= 0; i--) {
cout << setw(4) << setfill('0') << num[i];
}
cout << endl;
}
BigInt operator + (BigInt b) {
BigInt res;
//处理符号
if (!symbol &&a