⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 重载÷.cpp

📁 巨型整数类
💻 CPP
字号:
#include"head.h"

//-------------------巨型整数/巨型整数-----------------//
HugeInt operator/(const HugeInt &a,const HugeInt &b){
	HugeInt h,h0,h1,h2;
	h1=a,h2=b;
	int i,k=Depth/10;
	if(b==h) throw Divbyzero(); //抛出除0异常
	if(a<0L) h1=-h1;
	if(b<0L) h2=-h2;
	if(h1<h2) return h;  //返回值为0
	h.huge_t[0]=h1.huge_t[0] - h2.huge_t[0] + 1; //相除之后数的最大位数
	for( i=h.huge_t[0]; i>0; i--,k=Depth/10 ){
		while(k){
			h.huge_t[i]+=k;
			h0=h*h2;
			if(h0>h1){
				h.huge_t[i]-=k;
				k=k/10;
			}
		}
	}
	for(;h.huge_t[ h.huge_t[0] ]==0 && h.huge_t[0]>1; h.huge_t[0]--);
	if(a*b<0L) return -h;
	return h;
}


//-------------------巨型整数/字符串------------------//
HugeInt operator/(const HugeInt &h,const char *buf){
	HugeInt h0,h1,h2;
    char str[MAX*Digit + 1];
    strcpy(str,buf);
	h1.str_to_huge(str,h1);
	if(h1==0L) throw Divbyzero(); //抛出除0异常
	return h2=h/h1;
}

//-----------------巨型整数/长整型-------------------//
HugeInt operator/(const HugeInt &h,const long &n){
	HugeInt h0,h1,h2;
	h1.long_to_huge(n,h1);
	if(h1==0L) throw Divbyzero();  //抛出除0异常
	return h2=h/h1;
}

//-------------------字符串/巨型整数--------------------------//
HugeInt operator/(const char *buf,const HugeInt &h){
	HugeInt h0,h1,h2;
	char str[MAX*Digit + 1];
	strcpy(str,buf);
	h1.str_to_huge(str,h1);  //字符串转化成巨型整数
	if(h==0L)  throw Divbyzero();  //抛出除0异常
	return h2=h1/h;
}

//-----------------长整型/字符串----------------------------//
HugeInt operator/(const long &n,const HugeInt &h){
	HugeInt h0,h1,h2;
	h1.long_to_huge(n,h1);
    if(h==0L)  throw Divbyzero();  //抛出除0异常
	return h2=h1/h;
}

//-----------------巨型整数/=巨型整数-----------------------//
HugeInt HugeInt::operator/=(const HugeInt &h){
	*this=*this/h;
	return *this;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -