#include <iostream>
using namespace std;
class BigInt {
public:
const static int MAX = 10000; //表示大数允许的最大长度
BigInt() {
}
BigInt(char *s) {
*this = s;
}
BigInt(int d) {
*this = d;
}
BigInt operator=(const char *s) {
int len = strlen(s);
this->len = len;
for (int i = len - 1; i >= 0; i--) {
this->data[i] = s[len - 1 - i] - '0';
}
}
BigInt operator=(int d) {
char s[MAX];
int i = 0;
while (d) {
s[i++] = d % 10 + '0';
d /= 10;
}
*this = s;
}
//重载加法运算
BigInt operator+(const BigInt &rhs) {
BigInt result;
int c = 0; //表示进位
int max_len = max(this->len, rhs.len);
for (int i = 0; i <= max_len; i++) {
int s = this->data[i] + rhs.data[i] + c
c++实现无限大整数的加法
最新推荐文章于 2022-04-18 21:06:30 发布