全RE求助(关于运算符重载)
查看原帖
全RE求助(关于运算符重载)
135155
mortal05楼主2021/1/12 17:51

本地跑没有问题,一提交全RE了

#include <bits/stdc++.h>
using namespace std;
struct BigInt{
	static const int BASE=1e8;
	static const int WIDTH=8;
	vector <int> s;
	
	BigInt (long long num=0) {*this=num;}
	BigInt operator = (long long num){
		s.clear();
		do{
			s.push_back(num%BASE);
			num/=BASE;
		} while(num>0);
		return *this;
	}
	BigInt operator = (const string& str){
		s.clear();
		int x,len=(str.length()-1)/WIDTH+1;
		for(int i=0;i<len;i++){
			int end=str.length()-i*WIDTH;
			int start=max(0,end-WIDTH);
			sscanf(str.substr(start,end-start).c_str(),"%d",&x);
			s.push_back(x);
		}
		return *this;
	}
	BigInt operator + (const BigInt& b) const {
		BigInt c;
		c.s.clear();
		for(int i=0,g=0;;i++)
		{
			if(g==0&&i>=s.size()&&i>=b.s.size()) break;
			int x=g;
			if(i<s.size()) x+=s[i];
			if(i<b.s.size()) x+=b.s[i];
			c.s.push_back(x%BASE);
			g=x/BASE;
		}
		return c;
	}
	BigInt operator += (const BigInt& b) {
		*this=*this+b; return *this;
	}
	BigInt operator * (const BigInt& b) const {
		BigInt c; c.s.clear(); long long n;
		for(int i=0;i<b.s.size()+s.size();i++) c.s.push_back(0);
		for(int i=0;i<b.s.size();i++)
			for(int j=0;j<s.size();j++) {
				n=((long long)b.s[i])*((long long)s[j]);
				c.s[i+j+1]+=(c.s[i+j]+(int)(n%BASE))/BASE;
				c.s[i+j]=(c.s[i+j]+(int)(n%BASE))%BASE;
				c.s[i+j+2]+=(c.s[i+j+1]+(int)(n/BASE))/BASE;
				c.s[i+j+1]=(c.s[i+j+1]+(int)(n/BASE))%BASE;
			}
		for(int i=c.s.size()-1;i>0;i--) if(c.s[i]==0) c.s.pop_back();
		return c;			
	}
	BigInt print(){
		for(int i=s.size()-1;i>=0;i--) printf("%d",s[i]);
	}
	
};
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	BigInt a,b,c;
	a=s1;
	b=s2;
	c=a*b;
	
	c.print();
	
}












2021/1/12 17:51
加载中...