跳到正文

个人记录

高精

hekaiyu约 4 分钟
原文
文章信息与版本

文章信息

收录
2026年4月12日
更新
2026年4月12日
篇幅
约 4 分钟

版本

  1. v2当前
  2. v1

高精代码全集

C++
struct big{
	static const int base=10;
	static const int w=1;
	int top;
	int num[100005];
	big (long long l=0){*this=l;}
	big operator = (long long m){
		while(top){
			num[top--]=0;
		}
		while(m){
	         num[++top]=m%base;
			 m/=base;
		}
		return *this;
	}
	bool operator < (const big& b){
		if(top!=b.top)return top<b.top;
		for(int i=1;i<=b.top;i++){
			if(num[i]!=b.num[i])return num[i]<b.num[i];
		}
		return false;
	}
	big operator + (const big& a){
		big c=0;int i=0,l=max(top,a.top);
		for(i=1;i<=l+1;i++){
		    c.num[i]+=num[i]+a.num[i];
	        c.num[i+1]=c.num[i]/base;
			c.num[i]=c.num[i]%base;
		}
		if(c.num[l+1]==0)c.top=l;
		else c.top=l+1;
		return c;
	}
	big operator * (const int& b)const{
		big c=0;
		c.top=top+4;
		for(int i=1;i<=top+4;i++){
		    c.num[i]+=num[i]*b;
	        c.num[i+1]+=c.num[i]/base;
			c.num[i]=c.num[i]%base;
		}
		while(c.num[c.top]==0&&c.top>1){
			c.top--;
		}
		return c;
	}
	big operator - (const big& a){
		big c=0;
		for(int i=1;i<=top;i++){
		    c.num[i]+=num[i]-a.num[i]+10;
	        c.num[i+1]=c.num[i]/base-1;
			c.num[i]=c.num[i]%base;
		}
		c.top=top;
		while(c.num[c.top]==0&&c.top>1){
			c.top--;
		}
		return c;
	}
	big operator / (const int& a){
		big c=0;int s=0;
		for(int i=top;i>=1;i--){
		   s=s*10+num[i];
		   c.num[i]=s/a;
		   s=s%a;
		}
    	c.top=top;
		while(c.num[c.top]==0&&c.top>1){
			c.top--;
		}
		return c;
	}
	int operator % (const int& a){
		big c=0;int s=0;
		for(int i=top;i>=1;i--){
		   s=s*10+num[i];
		   c.num[i]=s/a;
		   s=s%a;
		}
    	c.top=top;
		while(c.num[c.top]==0&&c.top>1){
			c.top--;
		}
		return s;
	}
};
istream& operator >> (istream& in,big& a){;
		char s[10005];
		if(!(in>>s))return in;
		int b=strlen(s);
		for(int i=b;i>=1;i--){
			a.num[i]=s[b-i]-'0';}
		a.top=b;
		return in;
	}
ostream& operator << (ostream& out,big& a){
	for(int i=a.top;i>=1;i--){
        out<<a.num[i];
	}
	return out;
}
原文