蒟蒻重载运算符TLE 求助
查看原帖
蒟蒻重载运算符TLE 求助
828318
wssb1919810楼主2023/1/10 13:52

#5~11和#13TLE了QAQ

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef int itn;
const int mx=2e4+10;
struct bign{
	int l,s[mx];
	bign(){l=1, memset(s,0,sizeof(s));}
	bign(const int x){*this=x;}
	bign operator =(const int x){
		char str[25];
		sprintf(str,"%d",x);
		return *this=str;
	}
	bign operator =(const char *num){
		l=strlen(num);
		memset(s,0,sizeof(s));
		for(int i=1;i<=l;i++) s[i]=num[l-i]-'0';
		return *this;
	}
	bign operator +(const bign b){
		int len=l>b.l?l:b.l;
		bign c;
		for(int i=1;i<=len;i++) c.s[i]+=s[i]+b.s[i], c.s[i+1]+=c.s[i]/10, c.s[i]%=10;
		c.l=len+1; 
		c.clean();
		return c;
	}
	bign operator -(const bign b){
		bign c;
		for(int i=1;i<=l;i++){
			if(s[i]<b.s[i]) s[i]+=10, s[i+1]--;
			c.s[i]=s[i]-b.s[i];
		}
		c.l=l;
		c.clean();
		return c;
	}
	bign operator *(const bign b){
		bign c;
		for(int i=1;i<=l;i++) for(int j=1;j<=b.l;j++) c.s[i+j-1]+=s[i]*b.s[j], c.s[i+j]+=c.s[i+j-1]/10, c.s[i+j-1]%=10;
		c.l=l+b.l+1;
		c.clean();
		return c;
	}
	bign operator /(const bign b){
		bign c,f=0;
		for(int i=l;i>=1;i--){
			f=f*10, f.s[1]=s[i];
			while(f>=b) f=f-b,c.s[i]++;
		}
		c.l=l;
		c.clean();
		return c;
	}
	bign operator %(const bign b){
		bign c,f=0;
		for(int i=l;i>=1;i--){
			f=f*10, f.s[1]=s[i];
			while(f>=b) f=f-b,c.s[i]++;
		}
		f.l=l;
		f.clean();
		return f;
	}
	void clean(){while(l>1&&!s[l]) l--;}
	bool operator >(const bign b){
		if(l!=b.l) return l>b.l;
		for(int i=l;i>=1;i--) if(s[i]!=b.s[i]) return s[i]>b.s[i];
		return false;
	}
	bool operator <(const bign b){
		if(l!=b.l) return l<b.l;
		for(int i=l;i>=1;i--) if(s[i]!=b.s[i]) return s[i]<b.s[i];
		return false;
	}
	bool operator ==(const bign b){
		return !(*this>b)&&!(*this<b);
	}
	bool operator >=(const bign b){
		return !(*this<b);
	}
	bool operator <=(const bign b){
		return !(*this>b);
	}
};
istream& operator >>(istream &in, bign &b){
	string str;
	in>>str;
	b=str.c_str();
	return in;
}
ostream& operator <<(ostream &out, const bign &b){
	for(int i=b.l;i>=1;i--) out<<b.s[i];
	return out;
}
bign fun(int x){
	bign s=1;
	for(int i=1;i<=x;i++) s=s*i;
	return s;
}
int main(){
	bign a,b;
	cin>>a>>b;
	cout<<a/b;
	return 0;
}

求大佬帮助!

2023/1/10 13:52
加载中...