#include #include #include #define max 1300
#define base 10000
#define baselen 4
using namespace std;
//int countnub = 0;
//此大整數類用陣列 digital[max]表示乙個大整數;
//乙個 digital表示最大為 9999;
//len 表示目前整數的用到最大digital位,sign表示符號;
class int
;int ::int()
int int::cmp(int obj, int sel = 1)//sel若初始為0是絕對值比較
bool int::zero()
bool int:: odd()
int int::move()
}if(this->zero())sign = 1;
return *this;
}///
int int::operator =(int obj)
int int::operator = (int obj)
else len = 0;
return *this;
}int int::operator = (char *s)
digital[k] = 0;
while(i>=l)digital[k] = digital[k]*10 + s[l++] - '0';
if(k)len = k-(digital[k]==0);
else len = 0;
return *this;}/
int int::operator +(int obj)
else //異號變同號減法;
}int int::operator -(int obj)
else //異號變同號加:
}int int::operator *(int obj)
while(carry) product.digital[i+j++] = carry%base, carry /= base;
}i = maxlen-1;
while(i&&product.digital[i]==0)i--;
product.len = i;
if(product.zero())product.sign = 1;//確定符號
else product.sign = sign*obj.sign;
return product;
}int int::operator /( int obj)
if(x.cmp(obj)>=0)y = y+(z=1);
if(y.zero())y.sign=1;
else y.sign=flag;
return y;
}int int::operator %(int obj)
if(x.cmp(obj)>=0)x = x-obj;
if(x.zero())x.sign = 1;
else x.sign = sign;
return x;
}int int::shift(int k)
int main()
return 0;
}
模板整理 大數模板
include include include include include includeusing namespace std define maxn 9999 define maxsize 1000 define dlen 4 class bignum 建構函式 bignum const i...
大數模板1
分別使用c 中的運算子過載的方法來實現大數之間的數 算,包括加法 減法 乘法 除法 n次方 取模 大小比較 賦值以及輸入流 輸出流的過載。並且使用這個大數模板,順利ac了hdoj上的1134這個題目的catalan數計數問題。大數模板的 如下 include include include incl...
大數模板1
include include include include include include using namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum 建構函式 bignum const in...