c++大数板子

这篇博客主要介绍了如何使用C++进行大数的处理,包括大数的加减乘除等基本运算。作者提供了相关代码板子,并鼓励读者交流学习。
摘要由CSDN通过智能技术生成
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

/*
 * 完全大数模板
 * 输出cin>>a
 * 输出a.print();
 * 注意这个输入不能自动去掉前导0的,可以先读入到char数组,去掉前导0,再用构造函数。
 * by kuangbin GG.
 */
#define MAXN 9999
#define MAXSIZE 1010
#define DLEN 4

class BigNum
{
    private:
        int a[5000]; //可以控制大数的位数
        int len;
    public:
        BigNum(){len=1;memset(a,0,sizeof(a));} //构造函数
        BigNum(const ll); //将一个int类型的变量转化成大数
        BigNum(const char*); //将一个字符串类型的变量转化为大数
        BigNum(const 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 int &)const; //重载除法运算符,大数对一个整数进行相除运算

        BigNum operator^(const int &)const; //大数的n次方运算
        int operator%(const int &)const; //大数对一个int类型的变量进行取模运算
        bool operator>(const BigNum &T)const; //大数和另一个大数的大小比较
        bool operator>(const int &t)const; //大数和一个int类型的变量的大小比较
        void print(); //输出大数
};
BigNum::BigNum(const ll b) //将一个int类型的变量转化为大数
{
    ll c,d=b;
    len=0;
    memset(a,0,sizeof(a));
    while(
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值