完全正负大数模板(正负数加减乘除求模运算)~~~~~

原模板是从kuangbin的acm模板里copy过来的,根据博主的代码风格对于模板做了一些写法上的小调整,不过呢~

因为博主本人有强迫症(ACMer通病)~~~所以经过一个下午+晚上的修改,将原来只支持无符号大整数的运算改成了支持有符号大整数的运算~~乘法除法挺好修改的,对于新的加法减法写了两个只支持无符号大数的加减法,根据运算符两边的符号位决定运算方式~~~顺便加上了大整数之间的除法运算和几个比较运算符~

模板检查了些许遍,应该没有啥bug了,除了输入-0(本来就不应该吗~)~~~~(有发现的童鞋一定要戳我~~~)

检验状况:


附上模板吧

//Copy from kuangbin~,modify by Siryuanshao
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>
#define MAXN 999999999
#define MAXSIZE 5000
#define DLEN 9
using namespace std;
class BigInt
{
    private:
        int a[500];
        int len;
        bool sign;
        //sign表示符号位的正负~
    protected:
        BigInt add(const BigInt&,const bool)const;
        BigInt subtract(const BigInt&,const bool)const;
         //两个无符号整形的加减法,flag标明结果的符号位~~
    public:
        BigInt() {sign=false;len=1;memset(a,0,sizeof(a));}
        BigInt(const int);
        BigInt(const char*);
        BigInt(const BigInt&);
        BigInt& operator=(const BigInt&);
        friend istream& operator>>(istream&,BigInt&);
        friend ostream& operator<<(ostream&,const BigInt&);
        friend BigInt abs(const BigInt&);

        BigInt operator+(const BigInt&)const;
        BigInt operator-(const BigInt&)const;
        BigInt operator*(cons
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值