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

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

?? bignum.cpp

?? This program is to handle all possible arithmetic operations (+, -, *, /, %) and logic operations (<
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include <iostream.h>
#include <string.h>
#define SIZE 120

class bigInt {
public:
	bigInt(char aBigInt[], bool negativeFlag = false, bool zeroFlag = false) { strcpy(a, aBigInt); setNegative(negativeFlag); setZero(zeroFlag); }
	bigInt() { clear(a); setNegative(false); setZero(true); }
	~bigInt() {};
	
	bool getNegative(void) { return negative; }
	bool getZero(void) { return zero; }
	void setNegative(bool negativeFlag) { negative = negativeFlag; }
	void setZero(bool zeroFlag) { zero = zeroFlag; }
	
	const bigInt& operator=(const bigInt& rhs);
	const bigInt& operator+(bigInt& b);
	const bigInt& operator*(bigInt& b);
	const bigInt& operator-(bigInt& b);
	const bigInt& operator/(bigInt& b);
	const bigInt& operator%(bigInt& b);
	const void operator+=(bigInt& b);
	const void operator*=(bigInt& b);
	const void operator-=(bigInt& b);
	const void operator/=(bigInt& b);
	const void operator%=(bigInt& b);
	const bool operator>(bigInt& b);
	const bool operator<(bigInt& b);
	const bool operator==(bigInt& b);
	const bool operator!=(bigInt& b);
	const bool operator>=(bigInt& b);
	const bool operator<=(bigInt& b);
	
	void getValue(char thisBigInt[]) {strcpy(thisBigInt, a); } // return a string which is equivalent to the number
	void setValue(char thisBigInt[]) {strcpy(a, thisBigInt); } // set string thisBigInt to the value of an instance
	int getLength() { return strlen(a); }
	char getDigit(int pos) { return a[pos]; } // return CHARACTER at position i
	void setDigit(int pos, char value) { a[pos] = value; } // set CHARACTER at position i to value
	void print() { for (int i = 0; i < getLength(); i++) cout << a[i]; }
	void reverse(void);
	void clear(char ar[]) { ar[0] = '0'; ar[1] = '\0'; }
	void fixArray(char ar[]);

private:
	char a[SIZE];
	bool negative;
	bool zero;
	//helper functions
	int value(char c) { return c - 48; } //convert a character into the digit form
	char represent(int k) { return (char)(k + 48); } //convert a digit into the character form
	int maximum(int a, int b) { return (a > b) ? a : b; }
};

void bigInt::fixArray(char ar[])
{
	int j = 0;
	int len = strlen(ar);
	while ((ar[j] == '0') && (j < len))
		j++;
	if (j == len)
		clear(ar);
	else {
		for (int i = 0; i < len - j; i++)
			ar[i] = ar[i + j];
		ar[len - j] = '\0';
	}
}

const bigInt& bigInt::operator=(const bigInt& rhs)
{
	if (this != &rhs) {			// check for self assignment
		negative = rhs.negative;
		zero = rhs.zero;
		strcpy(a, rhs.a);
	}
	return *this;	//enable cascading
}

//reverse a string
void bigInt::reverse(void)
{
	int len = getLength();
	for (int i = 0; i < len/2; i++) {
		char temp = a[i];
		a[i] = a[len-1-i];
		a[len-1-i] = temp;
	}
}

//========================================== Multiplication function ==============================//
const bigInt& bigInt::operator*(bigInt& b)
{
	int len1 = getLength(), len2 = b.getLength();
	int i = 0, j = 0;
	int carry[SIZE][SIZE];
	int r[SIZE][SIZE];

	//reverse 2 number for the convenience in computing
	reverse();
	b.reverse();
	
	//initialize carry[][] and r[][]
	for (i = 0; i <SIZE; i++)
		for (j = 0; j < SIZE; j++) {
			carry[i][j] = 0;
			r[i][j] = 0;
	}

	//fill digits into the array r, which is the temp table in multiplying 2 numbers
	for (i = 0; i < len2; i++) {
		
		for (j = 0; j < len1; j++) {
			
			int x = value(getDigit(j));
			int y = value(b.getDigit(i));
			if (j != 0) {

				r[i][j+i] = (x * y + carry[i][j+i-1]) % 10; // each digit is computed from the product of 2 digits from the operands and the carry from the previous computation
				carry[i][j+i] = (x * y + carry[i][j+i-1]) /10;
				
			}
			else {
				r[i][j+i] = x * y % 10;
				carry[i][j+i] = x * y / 10;
			}
			
		}
		r[i][len1+i] = carry[i][len1+i-1];
		
	}
	
	int carry1[SIZE]; //carry array for the final product
	int tempResult[SIZE]; //final product in digit form
	
	//initialize carry1[] and tempResult[]
	for (i = 0; i < SIZE; i++)
		carry1[i] = 0;
	for (i = 0; i < SIZE; i++)
		tempResult[i] = 0;

	//compute tempResult from the temp table
	for (i = 0; i < len1 + len2; i++) {
		for (j = 0; j < len2; j++)
			tempResult[i] += r[j][i];
		if (i == 0) {
			carry1[i] = tempResult[i] / 10;
			tempResult[i] = tempResult[i] % 10;
		}
		else {
			int temp = tempResult[i];
			tempResult[i] = (temp + carry1[i-1]) % 10;
			carry1[i] = (temp + carry1[i-1]) / 10;
		}
	}
	
	char result[SIZE];
	//convert the final product in digit form into character form
	for (i = 0; i < len1 + len2; i++)
		result[i] = represent(tempResult[i]);
	
	//check if there is a '0' at the beginning of the product
	if (value(result[len1 + len2 - 1]) == 0)
		result[len1 + len2 - 1] = '\0'; // if so, obmit it
	else
		result[len1 + len2] = '\0';
	
	//reverse the operands to get back the original value
	reverse();
	b.reverse();
	//reverse the final result in character form to obtain the correct order
	bigInt returnResult(result);
	returnResult.reverse();

	return returnResult;
}
//=================================================================================================//

//========================================== Addition function ====================================//
const bigInt& bigInt::operator+(bigInt& b)
{
	int len1 = getLength(), len2 = b.getLength();
	int i = 0;
	
	//reverse 2 number for the convenience in computing
	reverse();
	b.reverse();
			
	int numA[SIZE], numB[SIZE];
	int carry[SIZE]; //carry array for the sum
	int tempResult[SIZE]; //sum in digit form
	
	//initialize numA[] and numB[]
	for (i = 0; i < SIZE; i++) {
		numA[i] = 0;
		numB[i] = 0;
	}

	if (len1 > len2) {
		for (i = 0; i < len1; i++)
			numA[i] = value(getDigit(i));
		for (i = 0; i < len2; i++)
			numB[i] = value(b.getDigit(i));
		for (i = len2; i < len1; i++)
			numB[i] = 0;
	}
	else {
		for (i = 0; i < len1; i++)
			numA[i] = value(getDigit(i));
		for (i = 0; i < len2; i++)
			numB[i] = value(b.getDigit(i));
		for (i = len1; i < len2; i++)
			numA[i] = 0;
	}

	//initialize carry[] and tempResult[]
	for (i = 0; i < SIZE; i++)
		carry[i] = 0;
	for (i = 0; i < SIZE; i++)
		tempResult[i] = 0;

	int len = maximum(len1, len2);
	//compute tempResult
	for (i = 0; i < len + 1; i++) {
		tempResult[i] = numA[i] + numB[i];
		if (i == 0) {
			carry[i] = tempResult[i] / 10;
			tempResult[i] = tempResult[i] % 10;
		}
		else {
			int temp = tempResult[i];
			tempResult[i] = (temp + carry[i-1]) % 10;
			carry[i] = (temp + carry[i-1]) / 10;
		}
	}
	tempResult[len+1] = carry[len];
	
	char result[SIZE];
	//convert the final product in digit form into character form
	for (i = 0; i < len + 1; i++)
		result[i] = represent(tempResult[i]);
	
	//check if there is a '0' at the beginning of the product
	if (value(result[len]) == 0)
		result[len] = '\0'; // if so, obmit it
	else
		result[len + 1] = '\0';
	
	reverse();
	b.reverse();
	//reverse the final result in character form to obtain the correct order
	bigInt returnResult(result);
	returnResult.reverse();
	
	return returnResult;
}
//=================================================================================================//

//========================================== Subtraction function =================================//
const bigInt& bigInt::operator-(bigInt& b)
{
	int len1 = getLength(), len2 = b.getLength();
	int i = 0, j;
	bool negativeFlagOfResult = false;
	bool zeroFlagOfResult = false;
	
	int numA[SIZE], numB[SIZE];
	int carry[SIZE]; //carry array for the sum
	int tempResult[SIZE]; //sum in digit form
	
	char result[SIZE];
	//initialize result[]
	for (i = 0; i < SIZE; i++)
		result[i] = '0';

	//initialize numA[] and numB[]
	for (i = 0; i < SIZE; i++) {
		numA[i] = 0;
		numB[i] = 0;
	}

	if (*this > b) { //positive number
		negativeFlagOfResult = false;
		zeroFlagOfResult = false;
		reverse();
		b.reverse();
		for (i = 0; i < len1; i++)
			numA[i] = value(getDigit(i));
		for (i = 0; i < len2; i++)
			numB[i] = value(b.getDigit(i));
		for (i = len2; i < len1; i++)
			numB[i] = 0;
	}
	else if (*this < b) { //negative number
		negativeFlagOfResult = true;
		zeroFlagOfResult = false;
		reverse();
		b.reverse();
		for (i = 0; i < len1; i++)
			numB[i] = value(getDigit(i));
		for (i = 0; i < len2; i++)
			numA[i] = value(b.getDigit(i));
		for (i = len1; i < len2; i++)
			numB[i] = 0;
	}
	else {
		negativeFlagOfResult = false;
		zeroFlagOfResult = true;
		clear(result);
		bigInt returnResult(result, negativeFlagOfResult, zeroFlagOfResult);
		returnResult.reverse();
		return returnResult;
	}
	
	//initialize carry[] and tempResult[]
	for (i = 0; i < SIZE; i++)
		carry[i] = 0;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
免费欧美日韩国产三级电影| 色呦呦国产精品| 亚洲天堂a在线| 国产精品免费观看视频| 国产欧美日韩卡一| 国产精品久久久久久福利一牛影视 | 另类中文字幕网| 精品一区二区三区日韩| 日本不卡一区二区| 麻豆国产精品777777在线| 久久99久久久欧美国产| 在线精品视频一区二区| 欧美一区二区三区免费大片| 欧美不卡123| 国产日韩精品一区二区浪潮av| 亚洲成人精品在线观看| 国产一区视频导航| 99在线精品视频| 欧美日本一道本| 久久免费国产精品| 亚洲欧美激情小说另类| 麻豆精品在线观看| 欧美日韩美少妇| 亚洲午夜激情网页| 国产一区二区三区四区五区入口 | 韩国精品主播一区二区在线观看| 国产一区高清在线| 精品久久国产老人久久综合| 男女性色大片免费观看一区二区| 欧美午夜精品久久久久久孕妇| 日韩亚洲电影在线| 国产精品国产三级国产普通话99| 色爱区综合激月婷婷| 欧美日韩成人综合| 亚洲一区二区在线免费看| 韩国精品在线观看| 日韩精品一区二区三区swag| 亚洲天堂2014| 99在线精品免费| 亚洲综合在线免费观看| 国产原创一区二区三区| 欧美精品一区男女天堂| 亚洲高清免费在线| 欧美日韩国产123区| 亚洲成av人片| 欧美精品在线观看一区二区| 久久久久久久久久久久电影 | 91看片淫黄大片一级| 日韩女优毛片在线| 裸体健美xxxx欧美裸体表演| 日韩丝袜美女视频| 国产精品一区不卡| 日韩一区二区中文字幕| 精品中文字幕一区二区| 中文文精品字幕一区二区| 日产国产欧美视频一区精品| 91精品国产全国免费观看| 极品少妇xxxx精品少妇| 中文字幕二三区不卡| 91福利精品视频| 蜜桃视频在线一区| 国产亚洲成av人在线观看导航| 久久精品国产亚洲高清剧情介绍 | 日韩免费一区二区| 盗摄精品av一区二区三区| 精品国产91久久久久久久妲己 | 蜜桃一区二区三区在线观看| 国产欧美1区2区3区| 91农村精品一区二区在线| 午夜在线电影亚洲一区| 久久一二三国产| 韩日精品视频一区| 亚洲免费av观看| 日韩午夜在线播放| 91亚洲精品一区二区乱码| 天堂蜜桃一区二区三区| 欧美高清你懂得| 国产99久久久精品| 亚洲视频一区二区免费在线观看| 欧美精品一卡二卡| 成人avav影音| 一区二区高清免费观看影视大全| 日韩欧美国产系列| 色播五月激情综合网| 国产真实乱子伦精品视频| 亚洲午夜一区二区| 欧美国产日本韩| 日韩欧美激情一区| 欧美在线综合视频| 成人免费看视频| 精品一区二区三区在线观看| 亚洲精品欧美专区| 欧美疯狂做受xxxx富婆| av不卡在线播放| 韩国毛片一区二区三区| 偷窥少妇高潮呻吟av久久免费| 日韩欧美国产不卡| 在线不卡一区二区| 在线亚洲欧美专区二区| 岛国一区二区三区| 国产一区二区主播在线| 日本成人在线一区| 亚洲电影视频在线| 亚洲一区二区四区蜜桃| 亚洲图片欧美激情| 中文字幕中文字幕在线一区| 久久久国产精品不卡| 精品国产乱码91久久久久久网站| 欧美精品色一区二区三区| 欧美网站一区二区| 在线亚洲+欧美+日本专区| 9l国产精品久久久久麻豆| 国产精品综合二区| 福利电影一区二区三区| 国产成人精品一区二| 亚洲电影欧美电影有声小说| 亚洲一区国产视频| 亚洲v中文字幕| 亚洲444eee在线观看| 日韩综合小视频| 日本亚洲最大的色成网站www| 三级欧美在线一区| 日韩精品国产欧美| 久久国产精品免费| 国产一二三精品| 精品一区二区三区在线观看国产| 韩国精品一区二区| 成人一级黄色片| 不卡的电影网站| 91黄色免费观看| 欧美日韩成人综合在线一区二区| 欧美日韩国产首页| 精品区一区二区| 久久精品人人爽人人爽| 国产精品不卡视频| 亚洲国产中文字幕在线视频综合| 日韩精彩视频在线观看| 激情综合五月婷婷| 99精品视频在线播放观看| 国产一区二区免费在线| voyeur盗摄精品| 欧美三级日韩在线| 欧美亚洲图片小说| 日韩一区二区免费电影| 国产亚洲精品aa午夜观看| 亚洲伦理在线精品| 蜜桃精品视频在线| 成人av在线网站| 欧美日韩不卡一区| 国产日韩精品一区二区三区| 一区二区不卡在线播放 | 成人短视频下载| 欧美日韩高清一区| 亚洲国产高清在线| 亚洲成人动漫在线观看| 国产精品一区二区视频| 欧美特级限制片免费在线观看| 精品999在线播放| 亚洲一区在线看| 成人综合激情网| 日韩一区二区三区视频在线观看| 国产精品久久三| 美国欧美日韩国产在线播放| 99re成人在线| 2欧美一区二区三区在线观看视频| 亚洲视频你懂的| 国产精品白丝jk黑袜喷水| 欧美日韩视频在线一区二区| 久久综合九色综合97婷婷女人 | 欧美一二三区精品| 亚洲天堂网中文字| 国产精品自拍一区| 日韩免费高清av| 视频一区二区三区在线| 91美女蜜桃在线| 国产日韩一级二级三级| 视频在线观看一区二区三区| 91视频.com| 国产精品免费久久| 国产乱码一区二区三区| 91.com视频| 国产调教视频一区| 麻豆一区二区在线| 欧美视频在线观看一区二区| 中文字幕中文字幕一区| 国产高清无密码一区二区三区| 日韩一区二区三区视频| 亚洲成人动漫在线观看| 在线视频一区二区三区| 国产精品久久久久久久浪潮网站| 国内久久婷婷综合| 欧美刺激午夜性久久久久久久| 亚洲电影你懂得| 欧美日韩免费电影| 亚洲香蕉伊在人在线观| 欧美亚日韩国产aⅴ精品中极品| 综合精品久久久| 97久久精品人人做人人爽50路| 中文字幕欧美日韩一区| 高清成人在线观看|