亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美日韩情趣电影| 国产精品美女久久久久aⅴ | 欧美精品色综合| 色综合夜色一区| 欧美日韩不卡一区二区| 91官网在线免费观看| 亚洲美女在线一区| 欧美福利电影网| 国内欧美视频一区二区| 国产在线麻豆精品观看| 91麻豆精东视频| 亚洲成av人综合在线观看| 欧美日韩免费观看一区三区| 欧美日韩国产综合一区二区| 琪琪久久久久日韩精品| 国产三级三级三级精品8ⅰ区| 丁香天五香天堂综合| 一区二区三区日韩欧美| 91精品国产综合久久福利软件| 另类小说综合欧美亚洲| 国产精品天天摸av网| 欧美在线观看一区| 精品一区二区综合| 亚洲欧美一区二区三区国产精品 | 韩日欧美一区二区三区| 国产精品夫妻自拍| 国产精品视频观看| 国产福利一区在线观看| 亚洲精品伦理在线| 日韩午夜精品视频| 色综合天天综合色综合av| 成人综合婷婷国产精品久久| 亚洲女子a中天字幕| 欧美美女直播网站| 成人理论电影网| 日本成人在线电影网| 国产精品国产三级国产aⅴ原创| 欧美性感一类影片在线播放| 国产精品99久久不卡二区| 亚洲成人精品一区二区| 亚洲国产成人自拍| 欧美xxxxx裸体时装秀| 91麻豆产精品久久久久久 | 精品国产一区二区三区忘忧草| 色综合夜色一区| 国产99精品在线观看| 免费看欧美女人艹b| 亚洲午夜激情av| 免费在线视频一区| 日韩av中文在线观看| 国产精品久久久久久久久搜平片 | av不卡在线观看| 另类小说综合欧美亚洲| 亚洲一区二区三区四区不卡| 国产精品高潮呻吟| 久久精品人人做人人爽人人| 日韩一卡二卡三卡| 欧美日韩一区二区在线观看视频| www.日韩大片| 激情深爱一区二区| 天天综合日日夜夜精品| 亚洲自拍偷拍av| 亚洲综合成人在线视频| 99精品桃花视频在线观看| 色综合色综合色综合色综合色综合| 久久精品亚洲一区二区三区浴池| 欧美无砖专区一中文字| 色88888久久久久久影院野外| 国产成人精品综合在线观看| 国内精品久久久久影院一蜜桃| 免费看欧美美女黄的网站| 日韩电影免费在线观看网站| 首页国产丝袜综合| 午夜影院久久久| 香蕉av福利精品导航| 天堂久久久久va久久久久| 午夜精品福利一区二区三区蜜桃| 性做久久久久久免费观看欧美| 亚洲国产综合色| 午夜一区二区三区视频| 视频一区免费在线观看| 免费观看一级欧美片| 久久99精品久久久| 国产一区二区不卡| 国产福利一区二区三区视频在线 | 亚洲三级小视频| 亚洲欧美另类久久久精品| 亚洲综合一区二区精品导航| 亚洲成人7777| 蜜臀av一区二区在线观看| 久久电影网站中文字幕| 国产一区不卡视频| 成人精品小蝌蚪| 色综合久久88色综合天天6| 色综合久久天天| 欧美日韩成人激情| 欧美不卡在线视频| 国产欧美综合在线观看第十页| 国产精品护士白丝一区av| 综合久久国产九一剧情麻豆| 亚洲一区av在线| 看片网站欧美日韩| 波多野结衣中文字幕一区| 91久久一区二区| 日韩你懂的在线播放| 国产三级精品在线| 亚洲大片一区二区三区| 国产精品资源网| 欧美亚洲综合网| 久久一二三国产| 亚洲三级在线免费观看| 免费欧美高清视频| 97精品久久久久中文字幕| 欧美精品99久久久**| 国产日产欧产精品推荐色| 亚洲国产裸拍裸体视频在线观看乱了| 美腿丝袜亚洲三区| aaa亚洲精品一二三区| 欧美一级黄色大片| 亚洲日本在线视频观看| 麻豆成人综合网| 色婷婷av一区二区| 久久影院视频免费| 亚洲成人你懂的| 白白色亚洲国产精品| 日韩无一区二区| 亚洲欧美日韩电影| 国产一区二区视频在线| 欧美日韩亚洲综合在线| 国产女主播一区| 免费高清成人在线| 欧美制服丝袜第一页| 国产精品国产三级国产专播品爱网| 91久久久免费一区二区| 久久影视一区二区| 亚洲成国产人片在线观看| heyzo一本久久综合| 26uuu国产电影一区二区| 亚洲1区2区3区4区| 日本高清无吗v一区| 中文字幕欧美日本乱码一线二线| 蜜桃av一区二区| 欧美日韩国产中文| 一区二区三区资源| kk眼镜猥琐国模调教系列一区二区 | 亚洲欧洲韩国日本视频| 国产综合色在线| 日韩免费观看高清完整版在线观看| 亚洲乱码国产乱码精品精可以看| 国产91丝袜在线播放0| 日韩精品中文字幕在线不卡尤物 | 日韩美女视频在线| 亚洲国产精品视频| 91福利在线观看| 亚洲狼人国产精品| 99久久久无码国产精品| 国产欧美日韩在线| 国产精品一二二区| 2020日本不卡一区二区视频| 老汉av免费一区二区三区| 欧美福利一区二区| 日韩国产在线观看一区| 538prom精品视频线放| 午夜久久福利影院| 3d动漫精品啪啪| 丝袜美腿成人在线| 欧美欧美欧美欧美| 午夜影院在线观看欧美| 欧美裸体一区二区三区| 日日摸夜夜添夜夜添亚洲女人| 欧美日本一区二区三区| 婷婷国产v国产偷v亚洲高清| 欧美日韩美少妇| 午夜激情一区二区| 日韩一区二区免费在线电影| 久久国产精品99久久人人澡| 亚洲精品一区二区三区蜜桃下载 | 欧美日韩1区2区| 亚洲v日本v欧美v久久精品| 这里只有精品99re| 毛片基地黄久久久久久天堂| www亚洲一区| 成人免费视频一区| 亚洲精品大片www| 精品污污网站免费看| 老司机免费视频一区二区三区| 久久久久国产精品麻豆ai换脸| 国产不卡视频一区| 亚洲天堂成人在线观看| 欧美视频三区在线播放| 美女爽到高潮91| 国产视频一区二区三区在线观看| 成+人+亚洲+综合天堂| 亚洲黄色小说网站| 91精品国产综合久久久久久| 国产精品综合二区| 夜夜操天天操亚洲| 久久综合狠狠综合久久综合88| 成人听书哪个软件好| 亚洲国产日日夜夜|