0分求调
查看原帖
0分求调
602624
___njr___楼主2023/2/23 13:47

#include<bits/stdc++.h>
using namespace std;
//#define frein(a)	freopen(a,"r",stdin)
//#define freout(a)	freopen(a,"w",stdout)
#define inline
class BigInt {
		/*
		* 倒序储存
		*/
		int a[5010];
		int len = 0;
	public:
		inline void operator++() {
			int i = 0 ;
			while(a[i]==9) {
				a[i++]=0;
			}
			++a[i];
		}
		inline bool operator==(BigInt other) {
			if(len != other.len) return false;
			for(int i= 0 ; i<len; ++i)if(a[i]^other.a[i])return false;
			return true;
		}
		inline void operator=(BigInt other) {
			len = other.len;
			memset(a,0,sizeof(a));
			for(int i = 0 ; i<len; ++i)a[i]=other.a[i];
			return;
		}
		inline void Pals_zero() {
			for(int i = len ; i>0 ; ++i)a[i] = a[i-1];
			a[0] = 0;
			++len;
		}
		inline BigInt operator + (BigInt other) {
			BigInt ret = (*this);
			int tmp=0;//进位
			int Len = max(len , other.len);
			for(int i = 0 ; i< Len ; ++i) {
				ret.a[i] += other.a[i]+tmp;
				tmp = ret.a[i] / 10;
				ret.a[i] %= 10;
			}
			if(tmp)ret.a[Len++] = tmp;
			ret.len = Len ;
			return ret;
		}
		inline void chulin() {
			while(!a[--len]);
			++len;
		}
//		inline BigInt operator-(BigInt other) {
//			BigInt ans;
//			int Len = max(len , other.len);
//			for(int i = 0 ; i < Len;++i)ans.a[i] = a[i]-other.a[i];
//			for(int i = 0 ; i < Len;++i)if(ans.a[i]<0){
//				ans.a[i]+=10;
//				--ans.a[i+1];
//			}
//			ans.len  =Len;
//			ans.Out() ;
//			ans.chulin();
//		}
		inline BigInt operator *  (BigInt other) {
			int tmp = 0 ;
			BigInt ans;
			int Len = len+other.len-1;
			for(int i = 0 ; i<len; ++i)for(int j = 0 ; j <other.len; ++j)ans.a[i+j]+=a[i]*other.a[j];
			for(int i = 0; i <Len; ++i)while(a[i]>=10) {
					a[i]-=10;
					++a[i+1];
				}
//			if(a[Len-1]>=10) {
//				a[Len]=a[Len-1]/10;
//				a[Len-1]%=10;
//				++Len;
//			}
			if(ans.a[Len])++Len;
			ans.len = Len;
			ans.chulin() ;
			return ans;
		}
		inline void Out() {
			BigInt other = *this;
			if(other.len = 0)putchar(48);
			else while(other.len)putchar(48+other.a[--other.len]);
		}
		inline void in() {
			string s;
			cin>>s;
			for(int i = 0 ; i <s.size(); ++i)a[i] = s[s.size()-i-1]-48;
			len = s.size();
		}
		inline void operator = (unsigned long long other) {
			BigInt ret;
			while(other) {
				ret.a[ret.len++] = other%10;
				other/=10;
			}
			(*this) = ret;
		}
};
int main() {
	BigInt a , b;
//	a = 999;
//	b=888;
	a.in();
	b.in();
	BigInt c = a*b;
	c.Out();
}

2023/2/23 13:47
加载中...