亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? biginteger.h

?? 使用分治技術
?? H
?? 第 1 頁 / 共 2 頁
字號:
#ifndef BIGINTEGER_H_H
#define BIGINTEGER_H_H
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include "GlobalObject.h"

using namespace std;

const int defaultSize = 50;

template <class T>
class BigInteger
{
public:
	BigInteger(const T* D, SYMBOL smbl);						//constructor

	BigInteger(int sz = defaultSize, SYMBOL smbl = PLUS);		//constructor

	BigInteger(const BigInteger<T>& obj);					//copy constructor
				
	~BigInteger(){											//destructor		
		delete []Data;
	}
	
	SYMBOL GetSymbol() const{									//return the symbol of big integer
		return Symbol;
	}

	void SetSymbol(SYMBOL smbl){								//set the symbol of big integer
		Symbol = smbl;
	}
	
	int Size() const{										//return the maximal size of a big integer
		return MaxSize;
	}

	int Length() const{										//return the length of a big integer	
		return Last + 1;
	}

	void SetLength(int newLen, const char& c = '0');		//set the length of a big integer

	T GetData(int i) const{									//get the ith value of a big integer	
		return (i > 0 && i <= Last + 1) ? Data[i - 1] : NULL;
	}

	void SetData(int i, const T& c);						//set the ith value of a big integer with char 'c'

	void FillNumber(const T& c);							//set the number with character 'c'

	bool IsEmpty() const{									//check if the big integer is null	
		return Last == -1 ? true : false;
	}

	bool IsFull() const{									//check if the length attains the maximal size of big integer
		return (Last == MaxSize - 1) ? true : false;
	}

	BigInteger<T> operator + (const BigInteger<T>& obj);			//addition

	BigInteger<T> operator - (const BigInteger<T>& obj);			//substraction

	BigInteger<T> operator * (const BigInteger<T>& obj);			//multiplication

	BigInteger<T> operator = (const BigInteger<T>& obj);	//overload operator '=' endow value

	bool operator > (const BigInteger<T>& obj);				//overload operator >

	bool operator < (const BigInteger<T>& obj);				//overload operator <

	bool operator == (const BigInteger<T>& obj);			//overload operator ==


	void Input();											//input a big integer

	void Output();											//output a big integer

	friend ifstream& operator >>(ifstream& in, BigInteger<T>& obj);
	
	friend ofstream& operator <<(ofstream& out,const BigInteger<T>& obj);

	friend int MinKthPower(int a, int b, const int& k);		//get the minimal value of a integer k of power while lager than a and b

	friend BigInteger<T> abs(const BigInteger<T>& obj);		//

	friend BigInteger<T> standardize(const BigInteger<T>& obj);		//

	friend BigInteger<T> PositiveIntSubstraction(const BigInteger<T>& a, const BigInteger<T> &b);

	friend BigInteger<T> TraditionalMultiplication(const BigInteger<T>& a, const BigInteger<T>& b);	//Traditional big integer Multiplication Algorithm

	friend BigInteger<T> OptimizedMultiplication(const BigInteger<T>& a, const BigInteger<T>& b, int div = 2);	//Optimized big integer Multiplication Algorithm

	friend BigInteger<T> LeftShift(const BigInteger<T>&a, int n);		//shift big integer to the left n bits

	friend BigInteger<T> OptimizedFuncion(BigInteger<T> M[], BigInteger<T> N[], int orignLen, int div);

	BigInteger<T> ZERO();									//define 0
private:
	int MaxSize;											//the maximal size of big integer
	int Last;												//the index of the highest bit of a big integer
	SYMBOL Symbol;											//denote the plus or minus of big integer, true:flus, otherwise minus
	T* Data;												//an array save the value of a big integer
	void Resize(int newSize);								//resize the size of big integer
};

#endif //BIGINTEGER_H_H

template <class T>
BigInteger<T>::BigInteger(const T* D, SYMBOL smbl /* = PLUS */){
	MaxSize = defaultSize;
	Last = -1;
	Symbol = smbl;
	Data = new T[defaultSize];
	const T* ptr = D;
	int bufLen = 0;
	while(*ptr) {
		bufLen++;
		ptr++;
	}

	if (bufLen > defaultSize) 
		Resize(bufLen);
	
	ptr = D;
	while(*ptr)
		Data[++Last] = *ptr++;
}

template <class T>
BigInteger<T>::BigInteger(int sz /* = defaultSize */, SYMBOL smbl){
	if (sz > 0)	{
		MaxSize = sz;
		Last = -1;
		Symbol = smbl;
		Data = new T[MaxSize];
		if (Data == NULL)		{
			cerr<<"Allocate Memory Error!"<<endl;
			exit(1);
		}
	}
}

template <class T>
BigInteger<T>::BigInteger(const BigInteger<T>& obj){
	MaxSize = obj.Size();
	Last = obj.Length() - 1;
	Symbol = obj.GetSymbol();

	Data = new T[MaxSize];

	if (Data == NULL)	{
		cerr<<"Allocate Memory Error!"<<endl;
		exit(1);
	}

	for (int i = 1; i <= Last + 1; i++)	{
		Data[i - 1] = obj.GetData(i);
	}
}

template <class T>
void BigInteger<T>::Resize(int newSize){
	if (newSize <= MaxSize)	{
		cerr<<"Invalid Size!"<<endl;
		exit(1);
	}
	if (newSize != MaxSize)	{
		T* newarr = new T[newSize];
		if (newarr == NULL)
		{
			cerr<<"Allocate Memory Error!"<<endl;
			exit(1);
		}

		int n = Last + 1;
//		int n = (Last + 1) < newSize ? Last + 1 : newSize;
		T* srcptr = Data;
		T* destptr = newarr;
		while (n--)		{
			*destptr++ = *srcptr++;
		}

		delete []Data;
		Data = newarr;
		MaxSize = newSize;
	}
}

template <class T>
void BigInteger<T>::SetLength(int newLen, const char& c /* =  */){
	if (newLen < 0)	{
		cerr<<"Invalid new length!";
		exit(1);
	}

	if (Length() >= newLen)
		Last = newLen - 1;						//刪除高位

	if (Length() < newLen) {
		if (MaxSize < newLen)
			Resize(newLen);
		for (int i = Length(); i < newLen; i++)
			Data[++Last] = c;					//填補高位	
	}
}

template <class T>
void BigInteger<T>::SetData(int i, const T& c){
	if (i > 0 && i <= Length())
		Data[i - 1] = c;
	else{
		cerr<<"Error in SetData!"<<endl;
		exit(1);
	}
}

template <class T>
void BigInteger<T>::FillNumber(const T& c){
	for (int i = 0; i <= Last; i++)
		Data[i] = c;
}

template <class T>
BigInteger<T> BigInteger<T>::operator + (const BigInteger<T>& obj){
	BigInteger<T> sum, a(*this), b(obj);
	SYMBOL sa = a.GetSymbol(), sb = b.GetSymbol(), ssum = PLUS;
	a = standardize(a);
	b = standardize(b);
	if (sa == sb) {													//同號相加
		ssum = sa;
		int Len1 = a.Length();
		int Len2 = b.Length();
		int Length = Len1 > Len2 ? Len1 : Len2;
		Len1 > Len2 ? b.SetLength(Length) : a.SetLength(Length);	//make up the shorted number same as the longer one
		sum.SetLength(Length);
		
		bool* C = new bool[Length + 1];								//mark (i-1)th carried
		C[0] = 0;
		for (int i = 1; i <= Length; i++){
			sum.SetData(i, a.GetData(i) + b.GetData(i) + C[i - 1] - 48);

			C[i] = 0;
			if (sum.GetData(i) > 57 && sum.GetData(i) <= 67)		{
				C[i] = 1;
				sum.SetData(i,sum.GetData(i) - 10); 
			}
		}
		if (C[Length])												
			sum.SetLength(Length + 1,'1');

		delete []C;		
	}
	else {															//異號相加
		a = abs(a);
		b = abs(b);
		if (a > b) {
			sum = a - b;
			ssum = sa;
		}
		else if (a < b) {
			sum = b - a;
			ssum = sb;
		}
		else 
			sum = ZERO();
	}
	sum.SetSymbol(ssum);	
	return sum;
}

template <class T>
BigInteger<T> BigInteger<T>::operator - (const BigInteger<T>& obj){
	BigInteger<T> ret, a(*this) ,b(obj);
	SYMBOL sa = a.GetSymbol(), sb = b.GetSymbol(), sret = PLUS;
	a = standardize(a);
	b = standardize(b);
	if (sa == sb) {													//同號相減
		ret = PositiveIntSubstraction(a, b);
		sret = ret.GetSymbol();
		if (sa == MINUS)					//兩個負數相減,設置符號
			sret = ret.GetSymbol() == PLUS ? MINUS : PLUS;
	}
	else {															//異號相減
		sret = sa;
		a = abs(a);
		b = abs(b);
		ret = a + b;
	}	

	ret.SetSymbol(sret);
	return ret;
}

template <class T>
BigInteger<T> BigInteger<T>::operator * (const BigInteger<T>& obj){
//	BigInteger<T> product = TraditionalMultiplication(*this, obj);
	BigInteger<T> product = OptimizedMultiplication(*this, obj, 2);

	return product;
}

template <class T>
BigInteger<T> BigInteger<T>::operator = (const BigInteger<T>& obj){
	MaxSize = obj.Size();
	Last = obj.Length() - 1;
	Symbol = obj.GetSymbol();

	Data = new T[MaxSize];
	
	if (Data == NULL){
		cerr<<"Allocate Memory Error!"<<endl;
		exit(1);
	}
	
	for (int i = 1; i <= Last + 1; i++)	{
		Data[i - 1] = obj.GetData(i);
	}

	return *this;
}

template <class T>
bool BigInteger<T>::operator > (const BigInteger<T>& obj){
	bool ret = true;

	BigInteger<T> a = *this, b = obj;
	a = standardize(a);
	b = standardize(b);

	SYMBOL sa = a.GetSymbol(), sb = b.GetSymbol();
	if (a == b)
		ret = false;

	if (sa == PLUS && sb == MINUS)
		ret = true;

	if (sa == MINUS && sb == PLUS)
		ret = false;

	if (sa == sb)
		if (sa == PLUS) {								//a and b are plus 
			if (a.Length() > b.Length()) 
				ret = true;
			else if (a.Length() < b.Length())
				ret = false;
			else
				for (int i = 1; i <= a.Length(); i++) 
					if (a.GetData(i) > b.GetData(i)) {
						ret = true;
						break;
					}
					else if (a.GetData(i) < b.GetData(i)) {
						ret = false;
						break;
					}
		}
		else{											//a and b are minus 
			if (a.Length() > b.Length()) 
				ret = false;
			else if (a.Length() < b.Length())
				ret = true;
			else
				for (int i = a.Length(); i >=1 ; i--) 
					if (a.GetData(i) > b.GetData(i)) {
						ret = false;
						break;
					}
					else if (a.GetData(i) < b.GetData(i)) {
						ret = true;
						break;
					}
		}

	return ret;
}

template <class T>
bool BigInteger<T>::operator < (const BigInteger<T>& obj){
	bool ret = true;

	BigInteger<T> a = *this, b = obj;
	a = standardize(a);
	b = standardize(b);

	SYMBOL sa = a.GetSymbol(), sb = b.GetSymbol();
	if (a == b)
		ret = false;

	if (sa == PLUS && sb == MINUS)
		ret = false;

	if (sa == MINUS && sb == PLUS)
		ret = true;

	if (sa == sb)
		if (sa == PLUS) {								//a and b are plus 
			if (a.Length() > b.Length()) 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧洲国产专区| 亚洲国产日韩一区二区| 激情综合五月天| 欧美精品久久久久久久多人混战 | 欧美少妇一区二区| 亚洲视频一二三| 99国内精品久久| 国产精品精品国产色婷婷| 国产69精品一区二区亚洲孕妇| 亚洲精品在线三区| 国模娜娜一区二区三区| 精品福利av导航| 国产在线观看免费一区| 久久久精品国产免大香伊| 国产91在线看| 国产精品福利一区二区| 91性感美女视频| 亚洲摸摸操操av| 欧美日韩视频不卡| 日本特黄久久久高潮| 日韩一区二区影院| 狠狠色综合日日| 国产日产欧美一区二区三区| av动漫一区二区| 一区二区三区av电影| 欧美日韩免费视频| 日韩av不卡在线观看| 欧美电视剧在线看免费| 国产真实乱对白精彩久久| 日本一区二区三区在线不卡| 白白色 亚洲乱淫| 亚洲一本大道在线| 欧美日产在线观看| 精品亚洲aⅴ乱码一区二区三区| 国产亚洲精品aa| 99精品国产视频| 亚洲成av人片在线观看| 日韩三级电影网址| 国产精品自在欧美一区| 中文字幕在线观看一区二区| 在线观看视频一区| 欧美在线观看你懂的| 亚洲v中文字幕| 久久亚洲一区二区三区四区| 成人ar影院免费观看视频| 一区二区免费视频| 日韩欧美www| 成人免费高清视频在线观看| 亚洲最新视频在线播放| 日韩一区二区在线观看视频| 粉嫩av亚洲一区二区图片| 亚洲综合一区在线| 精品奇米国产一区二区三区| eeuss鲁片一区二区三区在线观看| 一区二区三区资源| 欧美成人一区二区三区在线观看 | 99精品久久只有精品| 午夜精品123| 欧美国产综合一区二区| 欧美自拍丝袜亚洲| 国产一区亚洲一区| 一区二区日韩电影| 欧美成人艳星乳罩| 91麻豆免费看| 久久99国产精品免费网站| 91视频国产观看| 日本不卡视频在线| 专区另类欧美日韩| 日韩一二三区不卡| 一本到三区不卡视频| 精品一区二区三区视频在线观看| 亚洲日本丝袜连裤袜办公室| 日韩欧美一区二区久久婷婷| 99久久国产综合精品色伊| 老司机一区二区| 一区二区三区精品视频| 精品成人一区二区三区| 欧美午夜理伦三级在线观看| 国产精品自产自拍| 日本午夜精品视频在线观看 | 麻豆精品在线看| 亚洲精品网站在线观看| 久久综合色鬼综合色| 欧美三级视频在线播放| 成人免费黄色在线| 精品一区二区在线免费观看| 亚洲午夜久久久久久久久电影院 | av高清不卡在线| 精品一区二区三区免费视频| 亚洲高清免费视频| 自拍视频在线观看一区二区| 久久久久综合网| 欧美一区午夜精品| 91国内精品野花午夜精品| 国产成人av电影在线播放| 蜜桃av一区二区| 亚洲成年人影院| 亚洲精品成a人| 国产精品欧美一区喷水| 极品美女销魂一区二区三区| 午夜精品久久久久久久蜜桃app| 中文乱码免费一区二区| 精品欧美一区二区久久| 欧美日韩电影一区| 91美女蜜桃在线| 成人禁用看黄a在线| 久久99精品久久久久久动态图| 亚洲成人久久影院| 亚洲精品国产无天堂网2021| 欧美国产精品一区二区| 久久久蜜臀国产一区二区| 欧美成人伊人久久综合网| 欧美精品xxxxbbbb| 欧美午夜理伦三级在线观看| 91福利社在线观看| 91麻豆swag| 99久久免费国产| 国产99一区视频免费| 国模娜娜一区二区三区| 国内精品伊人久久久久av一坑| 爽爽淫人综合网网站| 亚洲午夜在线视频| 一区二区三区欧美视频| 夜夜精品视频一区二区| 亚洲欧美精品午睡沙发| 亚洲日本免费电影| 亚洲私人黄色宅男| 综合久久久久久久| 国产精品第一页第二页第三页 | 91精品国产综合久久久久| 欧美日本在线播放| 日韩综合一区二区| 日韩制服丝袜av| 视频精品一区二区| 秋霞av亚洲一区二区三| 日韩精品乱码av一区二区| 日韩精品一级二级 | 亚洲一区在线观看免费 | 青青草视频一区| 日韩**一区毛片| 久久超碰97人人做人人爱| 麻豆成人av在线| 国产一区二区在线观看免费| 国产91高潮流白浆在线麻豆| 99综合影院在线| 色999日韩国产欧美一区二区| 欧美中文字幕一区二区三区亚洲| 欧美视频在线观看一区二区| 欧美欧美午夜aⅴ在线观看| 欧美一区二区视频在线观看 | 国产日韩欧美亚洲| 国产精品女主播av| 亚洲精品日产精品乱码不卡| 一区2区3区在线看| 三级一区在线视频先锋| 精品在线一区二区三区| 成人黄色软件下载| 日本韩国视频一区二区| 欧美日韩国产精品自在自线| 日韩一本二本av| 中文字幕av一区二区三区| 亚洲激情六月丁香| 日韩国产精品久久久久久亚洲| 久久成人精品无人区| eeuss鲁片一区二区三区| 欧美日韩中文字幕一区二区| 免费日本视频一区| 国产91精品露脸国语对白| 色天天综合久久久久综合片| 欧美高清视频一二三区| 久久久久综合网| 亚洲激情自拍视频| 蜜芽一区二区三区| 成人午夜在线播放| 在线观看日韩一区| 精品三级av在线| 亚洲色图欧洲色图婷婷| 石原莉奈在线亚洲二区| 成人午夜看片网址| 欧美日韩精品三区| 久久久国产精品不卡| 亚洲精品欧美综合四区| 精品一区二区av| 色婷婷激情一区二区三区| 日韩一级片在线观看| 国产精品第一页第二页第三页| 日韩在线a电影| eeuss鲁片一区二区三区在线看| 3atv一区二区三区| 中文在线资源观看网站视频免费不卡| 亚洲另类春色国产| 久久疯狂做爰流白浆xx| 色先锋资源久久综合| 精品国产一区二区三区四区四| 亚洲视频你懂的| 久久精品国产免费| 91久久精品国产91性色tv| 久久亚洲影视婷婷| 午夜欧美大尺度福利影院在线看| 国产成人午夜视频|