📄 head.h
字号:
#ifndef HEAD_H
#define HEAD_H
#include<iostream>
#include<string>
#include<conio.h>
#include<memory> //包含大规模初始化头文件
#define Digit 4 //一个数组元素存放的位数个数
#define Depth 10000 //进制数
#define MAX 100 //数组的长度
using namespace std;
//------------函数申明--------------------//
class Divbyzero{}; //除0异常类
class Modbyzero{}; //模取0异常类
class OutofRange{}; //溢出异常类
class HugeInt;
ostream &operator<< (ostream &out, HugeInt &h );
istream &operator>> (istream &is, HugeInt &h );
HugeInt operator+(const HugeInt &a,const HugeInt &b); //巨型整数 + 巨型整数
HugeInt operator-(const HugeInt &a,const HugeInt &b); //巨型整数 - 巨型整数
HugeInt operator*(const HugeInt &a,const HugeInt &b); //巨型整数 * 巨型整数
HugeInt operator/(const HugeInt &a,const HugeInt &b); //巨型整数 / 巨型整数
HugeInt operator%(const HugeInt &a,const HugeInt &b); //巨型整数 % 巨型整数
HugeInt operator+(const HugeInt &a,const long &n); //巨型整数 + 长整型
HugeInt operator-(const HugeInt &a,const long &n); //巨型整数 - 长整型
HugeInt operator*(const HugeInt &a,const long &n); //巨型整数 * 长整型
HugeInt operator/(const HugeInt &a,const long &n); //巨型整数 / 长整型
HugeInt operator%(const HugeInt &a,const long &n); //巨型整数 % 长整型
HugeInt operator+(const HugeInt &a,const char *buf); //巨型整数 + 字符串
HugeInt operator-(const HugeInt &a,const char *buf); //巨型整数 - 字符串
HugeInt operator*(const HugeInt &a,const char *buf); //巨型整数 * 字符串
HugeInt operator/(const HugeInt &a,const char *buf); //巨型整数 / 字符串
HugeInt operator%(const HugeInt &a,const char *buf); //巨型整数 % 字符串
HugeInt operator+(const char *buf,const HugeInt &h); //字符串 + 巨型整数
HugeInt operator-(const char *buf,const HugeInt &h); //字符串 - 巨型整数
HugeInt operator*(const char *buf,const HugeInt &h); //字符串 * 巨型整数
HugeInt operator/(const char *buf,const HugeInt &h); //字符串 / 巨型整数
HugeInt operator%(const char *buf,const HugeInt &h); //字符串 % 巨型整数
bool operator>(const HugeInt &a,const HugeInt &b);
bool operator==(const HugeInt &a,const HugeInt &b);
bool operator<(const HugeInt &a,const HugeInt &b);
bool operator>=(const HugeInt &a,const HugeInt &b);
bool operator<=(const HugeInt &a,const HugeInt &b);
bool operator!=(const HugeInt &a,const HugeInt &b);
bool operator>(const HugeInt &a,const long &n);
bool operator==(const HugeInt &a,const long &n);
bool operator<(const HugeInt &a,const long &n);
bool operator>=(const HugeInt &a,const long &n);
bool operator<=(const HugeInt &a,const long &n);
bool operator!=(const HugeInt &a,const long &n);
bool operator>(const HugeInt &h1,const char *str);
bool operator==(const HugeInt &h1,const char *str);
bool operator<(const HugeInt &h1,const char *str);
bool operator>=(const HugeInt &h1,const char *str);
bool operator<=(const HugeInt &h1,const char *str);
bool operator!=(const HugeInt &h1,const char *str);
bool operator>(const char *str,const HugeInt &a);
bool operator<(const char *str,const HugeInt &a);
bool operator==(const char *str,const HugeInt &a);
bool operator>=(const char *str,const HugeInt &a);
bool operator<=(const char *str,const HugeInt &a);
bool operator!=(const char *str,const HugeInt &a);
bool operator>(const long &n,const HugeInt &a);
bool operator<(const long &n,const HugeInt &a);
bool operator==(const long &n,const HugeInt &a);
bool operator>=(const long &n,const HugeInt &a);
bool operator<=(const long &n,const HugeInt &a);
bool operator!=(const long &n,const HugeInt &a);
//------------------------------------------//
class HugeInt{
int huge_t[MAX+1]; //数组形式表示巨型整数
public:
HugeInt(){ //构造函数
for( int i=0; i<MAX ; i++ )
huge_t[i]=0;
}
HugeInt(const char *buf); //字符串构造函数
HugeInt(const long &n);//长整型构造函数
HugeInt(const HugeInt &h);//拷贝构造函数
void str_to_huge(const char *str,HugeInt &h); //字符串转化成巨型
void long_to_huge(const long &n,HugeInt &h); //长整型转化成巨型整数
friend ostream &operator<< (ostream &out, HugeInt &h );
friend istream &operator>> (istream &is, HugeInt &h );
friend HugeInt operator+(const HugeInt &a,const HugeInt &b); //巨型整数 + 巨型整数
friend HugeInt operator-(const HugeInt &a,const HugeInt &b); //巨型整数 - 巨型整数
friend HugeInt operator*(const HugeInt &a,const HugeInt &b); //巨型整数 * 巨型整数
friend HugeInt operator/(const HugeInt &a,const HugeInt &b); //巨型整数 / 巨型整数
friend HugeInt operator%(const HugeInt &a,const HugeInt &b); //巨型整数 % 巨型整数
HugeInt operator++(); //前置运算 ++巨型整数
HugeInt operator++(int nouse); //后置运算 巨型整数++
HugeInt operator--(); //前置运算 --巨型整数
HugeInt operator--(int nouse); //后置运算 巨型整数--
friend HugeInt operator+(const HugeInt &a,const long &n); //巨型整数 + 长整型
friend HugeInt operator-(const HugeInt &a,const long &n); //巨型整数 - 长整型
friend HugeInt operator*(const HugeInt &a,const long &n); //巨型整数 * 长整型
friend HugeInt operator/(const HugeInt &a,const long &n); //巨型整数 / 长整型
friend HugeInt operator%(const HugeInt &a,const long &n); //巨型整数 % 长整型
friend HugeInt operator+(const HugeInt &a,const char *buf); //巨型整数 + 字符串
friend HugeInt operator-(const HugeInt &a,const char *buf); //巨型整数 - 字符串
friend HugeInt operator*(const HugeInt &a,const char *buf); //巨型整数 * 字符串
friend HugeInt operator/(const HugeInt &a,const char *str); //巨型整数 / 字符串
friend HugeInt operator%(const HugeInt &a,const char *str); //巨型整数 % 字符串
friend HugeInt operator+(const char *buf,const HugeInt &h); //字符串 + 巨型整数
friend HugeInt operator-(const char *buf,const HugeInt &h); //字符串 - 巨型整数
friend HugeInt operator*(const char *buf,const HugeInt &h); //字符串 * 巨型整数
friend HugeInt operator/(const char *buf,const HugeInt &h); //字符串 / 巨型整数
friend HugeInt operator%(const char *buf,const HugeInt &h); //字符串 % 巨型整数
friend HugeInt operator+(const long &n,const HugeInt &h); //长整型 + 巨型整数
friend HugeInt operator-(const long &n,const HugeInt &h); //长整型 - 巨型整数
friend HugeInt operator*(const long &n,const HugeInt &h); //长整型 * 巨型整数
friend HugeInt operator/(const long &n,const HugeInt &h); //长整型 / 巨型整数
friend HugeInt operator%(const long &n,const HugeInt &h); //长整型 % 巨型整数
HugeInt operator+=(const HugeInt &h);
HugeInt operator-=(const HugeInt &h);
HugeInt operator*=(const HugeInt &h);
HugeInt operator/=(const HugeInt &h);
HugeInt operator%=(const HugeInt &h);
friend bool operator>(const HugeInt &a,const HugeInt &b); //关系运算符 > 重载
friend bool operator<(const HugeInt &a,const HugeInt &b); //关系运算符 < 重载
friend bool operator==(const HugeInt &a,const HugeInt &b); //关系运算符 == 重载
friend bool operator>=(const HugeInt &a,const HugeInt &b); //关系运算符>=重载
friend bool operator<=(const HugeInt &a,const HugeInt &b); //关系运算符>=重载
friend bool operator!=(const HugeInt &a,const HugeInt &b); //关系运算符>=重载
friend bool operator>(const HugeInt &a,const long &n); //关系运算符 > 重载
friend bool operator<(const HugeInt &a,const long &n); //关系运算符 < 重载
friend bool operator==(const HugeInt &a,const long &n); //关系运算符 == 重载
friend bool operator>=(const HugeInt &a,const long &n);
friend bool operator<=(const HugeInt &a,const long &n);
friend bool operator!=(const HugeInt &a,const long &n);
friend bool operator>(const HugeInt &h1,const char *str); //关系运算符 > 重载
friend bool operator<(const HugeInt &h1,const char *str); //关系运算符 < 重载
friend bool operator==(const HugeInt &h1,const char *str); //关系运算符 == 重载
friend bool operator>=(const HugeInt &h1,const char *str);
friend bool operator<=(const HugeInt &h1,const char *str);
friend bool operator!=(const HugeInt &h1,const char *str);
friend bool operator>(const char *str,const HugeInt &a);
friend bool operator<(const char *str,const HugeInt &a);
friend bool operator==(const char *str,const HugeInt &a);
friend bool operator>=(const char *str,const HugeInt &a);
friend bool operator<=(const char *str,const HugeInt &a);
friend bool operator!=(const char *str,const HugeInt &a);
friend bool operator>(const long &n,const HugeInt &a);
friend bool operator<(const long &n,const HugeInt &a);
friend bool operator==(const long &n,const HugeInt &a);
friend bool operator>=(const long &n,const HugeInt &a);
friend bool operator<=(const long &n,const HugeInt &a);
friend bool operator!=(const long &n,const HugeInt &a);
HugeInt &operator=(const HugeInt &h); //重载赋值运算符
HugeInt operator-(); //重载取反运算符
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -