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

📄 重载关系运算符.cpp

📁 巨型整数类
💻 CPP
字号:

#include"head.h"

bool operator>(const HugeInt &a,const HugeInt &b){  //关系运算符>重载

	if(a==b) return false;

	if( a.huge_t[ a.huge_t[0] ]>=0 && b.huge_t[ b.huge_t[0] ]>=0 ){ //最高位都大于或等于0

		if( a.huge_t[0]<b.huge_t[0] ) return false;  //a的位数比b的位数大
		
		if( a.huge_t[0]==b.huge_t[0] ){
			for(int i=a.huge_t[0]; i>0; i-- )
				if(a.huge_t[i]>b.huge_t[i])  return true; //位数相同,最高位a小于b
				else if(a.huge_t[i]<b.huge_t[i])  return false;
		}

		

		return true;

	}

   	if( a.huge_t[ a.huge_t[0] ]>0 && b.huge_t[ b.huge_t[0] ]<0) return true; //a的最高位大于0,b的最高位小于0,返回true

   if(a.huge_t[ a.huge_t[0] ]<0 && b.huge_t[ b.huge_t[0] ]>0 ) return false; //a的最高位小于0,b的最高位小于0,返回false

   	if(a.huge_t[ a.huge_t[0] ]<=0 && b.huge_t[ b.huge_t[0] ]<=0){   //最高位都小于或等于0

		if( a.huge_t[0]>b.huge_t[0] ) return false;  //a的位数比b的位数大
		
		if( a.huge_t[0]==b.huge_t[0]){
			for(int j=a.huge_t[0]; j>0; j-- )
				if( a.huge_t[j]>b.huge_t[j] )  return true; //位数相同,最高位a大于b
				else if(a.huge_t[j]<b.huge_t[j])  return false;
		}
		

	  return true;
	}
	return true;


}

bool operator==(const HugeInt &a,const HugeInt &b){  //关系运算符==重载

	if(a.huge_t[0]!=b.huge_t[0]) return false;
	if( a.huge_t[0]==b.huge_t[0]){
		for(int i=1; i<=a.huge_t[0]; i++)
			if(a.huge_t[i]!=b.huge_t[i]) return false;
	}
	return true;
		
}

bool operator<(const HugeInt &a,const HugeInt &b){  //关系运算符<重载
	if(a>b || a==b) return false;
	else return true;
}

bool operator>=(const HugeInt &a,const HugeInt &b){  //关系运算符>=重载
	if(a>b || a==b) return true;
		else return false;
}

bool operator<=(const HugeInt &a,const HugeInt &b){  //关系运算符<=重载
	if(a<b || a==b) return true;
	else return false;
}

bool operator!=(const HugeInt &h1,const HugeInt &h2){  //关系运算符!=重载
	if(h1==h2) return false;
	else return true;
}

//--------------巨型整数与长整型关系重载-------------------//
bool operator>(const HugeInt &h1,const long &n){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h1>h) return true;
	else return false;
}

bool operator<(const HugeInt &h1,const long &n){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h1<h) return true;
	else return false;
}

bool operator==(const HugeInt &h1,const long &n){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h1==h) return true;
	else return false;
}

bool operator>=(const HugeInt &h1,const long &n){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h1>=h) return true;
	else return false;
}

bool operator<=(const HugeInt &h1,const long &n){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h1<=h) return true;
	else return false;
}

bool operator!=(const HugeInt &h1,const long &n){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h1!=h) return true;
	else return false;
}

//----------------巨型整数与字符串关系重载---------------//
bool operator>(const HugeInt &h1,const char *str){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h1>h) return true;
	else return false;
}

bool operator<(const HugeInt &h1,const char *str){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h1<h) return true;
	else return false;
}

bool operator==(const HugeInt &h1,const char *str){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h1==h) return true;
	else return false;
}

bool operator>=(const HugeInt &h1,const char *str){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h1>=h) return true;
	else return false;
}

bool operator<=(const HugeInt &h1,const char *str){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h1<=h) return true;
	else return false;
}

bool operator!=(const HugeInt &h1,const char *str){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h1!=h) return true;
	else return false;
}


//------------字符串与巨型整数关系重载---------------//
bool operator>(const char *str,const HugeInt &h1){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h>h1) return true;
	else return false;
}

bool operator<(const char *str,const HugeInt &h1){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h<h1) return true;
	else return false;
}

bool operator==(const char *str,const HugeInt &h1){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h==h1) return true;
	else return false;
}

bool operator>=(const char *str,const HugeInt &h1){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h>=h1) return true;
	else return false;
}

bool operator<=(const char *str,const HugeInt &h1){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h<=h1) return true;
	else return false;
}

bool operator!=(const char *str,const HugeInt &h1){
	HugeInt h;
	h.str_to_huge(str,h);
	if(h!=h1) return true;
	else return false;
}

//----------长整型与巨型整数关系重载------------//
bool operator>(const long &n,const HugeInt &h1){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h>h1) return true;
	else return false;
}

bool operator<(const long &n,const HugeInt &h1){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h<h1) return true;
	else return false;
}

bool operator==(const long &n,const HugeInt &h1){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h==h1) return true;
	else return false;
}

bool operator>=(const long &n,const HugeInt &h1){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h>=h1) return true;
	else return false;
}

bool operator<=(const long &n,const HugeInt &h1){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h<=h1) return true;
	else return false;
}

bool operator!=(const long &n,const HugeInt &h1){
	HugeInt h;
	h.long_to_huge(n,h);
	if(h!=h1) return true;
	else return false;
}

⌨️ 快捷键说明

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