高精度模板
Posted pjykk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高精度模板相关的知识,希望对你有一定的参考价值。
持续更新。
code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#ifndef positive
#define positive 0
#endif
#ifndef negative
#define negative 1
#endif
using namespace std;
namespace __bignum
class __bigint
private:
int __data[1000010],__len,__symbol;
public:
void clear()
memset(__data,0,sizeof(__data));
__len=0;__symbol=positive;
__bigint()
memset(__data,0,sizeof(__data));
__len=0;__symbol=positive;
__bigint(int __num)
if(__num<0)__symbol=negative;__num*=-1;
else __symbol=positive;
while(__num)
__data[++__len]=__num%10;
__num/=10;
__bigint(char __num[])
if(__num[0]=='-')
__symbol=negative;
__len=strlen(__num)-1;
for(int i=1;i<=__len;i++)__data[__len-i+1]=__num[i]-'0';
else
__symbol=positive;
__len=strlen(__num);
for(int i=0;i<__len;i++)__data[__len-i]=__num[i]-'0';
__bigint(string __num)
if(__num[0]=='-')
__symbol=negative;
__len=__num.length()-1;
for(int i=1;i<=__len;i++)__data[__len-i+1]=__num[i]-'0';
else
__symbol=positive;
__len=__num.length();
for(int i=0;i<__len;i++)__data[__len-i]=__num[i]-'0';
__bigint(int __num[],int __l,int __sy)
for(int i=1;i<=__l;i++)__data[i]=__num[i];
__len=__l;__symbol=__sy;
friend istream &operator >>(istream &__input,__bigint& __num)
string s;__input >> s;
if(s[0]=='-')
__num.__symbol=negative;
__num.__len=s.length()-1;
for(int i=1;i<=__num.__len;i++)__num.__data[__num.__len-i+1]=s[i]-'0';
else
__num.__symbol=positive;
__num.__len=s.length();
for(int i=0;i<__num.__len;i++)__num.__data[__num.__len-i]=s[i]-'0';
return __input;
friend ostream &operator <<(ostream &__output,__bigint& __num)
if(__num.__symbol==negative)__output << '-';
for(int i=1;i<=__num.__len;i++)__output << __num.__data[__num.__len-i+1];
return __output;
void operator =(int __num)
clear();
if(__num<0)__symbol=negative;__num*=-1;
else __symbol=positive;
while(__num)
__data[++__len]=__num%10;
__num/=10;
void operator =(char __num[])
clear();
if(__num[0]=='-')
__symbol=negative;
__len=strlen(__num)-1;
for(int i=1;i<=__len;i++)__data[__len-i+1]=__num[i]-'0';
else
__symbol=positive;
__len=strlen(__num);
for(int i=0;i<__len;i++)__data[__len-i]=__num[i]-'0';
void operator =(string __num)
clear();
if(__num[0]=='-')
__symbol=negative;
__len=__num.length()-1;
for(int i=1;i<=__len;i++)__data[__len-i+1]=__num[i]-'0';
else
__symbol=positive;
__len=__num.length();
for(int i=0;i<__len;i++)__data[__len-i]=__num[i]-'0';
;
#undef positive
#undef negative
using namespace __bignum;
__bigint qwq;
int main()
//test
return 0;
以上是关于高精度模板的主要内容,如果未能解决你的问题,请参考以下文章