大数C++写法:加减乘除模板

本文详细介绍了如何使用C++编写大数运算的模板代码,涵盖了大数的加法、减法、乘法和除法操作。通过实例展示了如何处理大数的位运算和进位问题,为理解和实现大数算法提供了清晰的思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<iostream>
#include<ostream>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<vector>
#include<stack>
#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
typedef long long LL;
#define MOD 998244353
#define maxn 1005
#define pi acos(-1.0)
#define INF 1e-7
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAXBIT 1007
#define BITTYPE int

struct BigInt {
    BITTYPE bit[MAXBIT];
    bool negative;//负数标志

public:
    BigInt();                //默认构造函数,值为0
    BigInt(const int);        //构造函数
    BigInt(const char *);    //构造函数
    BigInt(const BigInt &);    //复制构造函数

    /*重载赋值运算符*/
    BigInt& operator=(const BigInt&);
    BigInt& operator=(const int        );

    /*重载算数运算符*/
    BigInt operator+(const BigInt&    )const;
    BigInt operator+(const int        )const;
    BigInt operator-(const BigInt&    )const;
    BigInt operator-(const int        )const;
    BigInt operator*(const BigInt&    )const;
    BigInt operator*(const int        )const;
    BigInt operator/(const int        )const;
    int    operator%(const int        )const;

    /*重载比较运算符*/
    bool operator>(const BigInt&    )const;
    bool operator>(const int        )const;
    bool operator>=(const BigInt&    )const;
    bool operator>=(const int        )const;
    bool operator<(const BigInt&    )const;
    bool operator<(const int        )const;
    bool operator<=(const BigInt&    )const;
    bool operator<=(const int        )const;
    bool operator==(const BigInt&    )const;
    bool operator==(const int        )const;
    bool operator!=(const BigInt&    )const;
    bool operator!=(const int        )const;

    void print()    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值