#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int M = 1e3+10;
const int MAXN = 9;
class BigNum {
public:
int a[M],len,sign;
void init();
void assignString(const char*);
void assignInt(LL);
LL toInt()const;
BigNum();
BigNum(LL);//int -> BigNum
BigNum(const char*);//char -> BigNum
BigNum(const BigNum &); //BigNum = BigNum
BigNum &operator = (const BigNum &);
friend istream& operator>>(istream&,BigNum&);
friend ostream& operator<<(ostream&,BigNum&);
BigNum operator + (const BigNum&)const;
BigNum operator - (const BigNum&)const;
BigNum operator * (const BigNum&)const;
BigNum operator / (const BigNum&)const ;
bool operator > (const BigNum&)const;
bool operator < (const BigNum&)const;
BigNum operator + (const LL&)const;//all
BigNum operator - (const LL&)const;//all
BigNum operator * (const LL&)const;//all
BigNum operator / (const LL&)const;//LL != 0 && BigNum all
BigNum operator ^ (const LL&)const;//LL >= 0 && BigNum >= 0
LL operator % (const LL&)const;//BigNum >=0 && LL > 0
};
void BigNum::init() {
len = 0;
sign = 1;
memset(a,0,sizeof(a));
}
void BigNum::assignString(const char *s) {
init();
int l = strlen(s);
int k = 0;
if(s[0] == '-') {
sign = -1;
k++;
}
int j = 0;
for(LL seed = 1; seed < MAXN; seed *= 10,j++) ;
bool flag = false;
for(int i = l-1; i >= k; i -= j) {
for(int jj = m
c++大数类
最新推荐文章于 2024-09-14 14:51:04 发布
本文介绍了C++中实现大数类(BigNum)的方法,包括大数的初始化、转换、基本运算(加减乘除)、比较操作以及输入输出。通过自定义大数类,可以进行大整数的高效处理和计算。
摘要由CSDN通过智能技术生成