#1#2#3#4#5#6 神奇错误,#1本地测试能过,luogu上wa掉
查看原帖
#1#2#3#4#5#6 神奇错误,#1本地测试能过,luogu上wa掉
590571
_weishiqi66_楼主2022/11/17 13:55
#include<bits/stdc++.h>
#define maxn 1000
using namespace std;
struct bigint{
	int len,f,a[maxn];
	bigint(int x=0){
		memset(a,0,sizeof(a));
		for(len=1;x;len++) a[len]=x%10,x/=10;
		len--;
	}
	int &operator[](int i){return a[i];}
	void f1(int l){
		len=l;
		for(int i=1;i<=len;i++) a[i+1]+=a[i]/10,a[i]%=10;
		for(;!a[len];) len--;
	}
	void f2(int l){
		len=l;
		for(int i=1;i<=len;i++) if(a[i]<0) a[i]+=10,a[i+1]--;
		for(;!a[len];) len--;
	}
	void read(){
		char c=getchar();
		while(c<'0'||c>'9') c=getchar();
		if(c>='0'&&c<='9') a[1]=c-'0';
		while(c>='0'&&c<='9'){
			for(int i=len+1;i>1;i--) a[i]=a[i-1];
			a[1]=c-'0';
			len++;
			c=getchar();
		}
		f1(len);
	}
	void print(){for(int i=max(len,1);i>=1;i--) printf("%d",a[i]);}
};
void fswap(bigint &a,bigint &b){bigint t=a;a=b;b=t;}
bool operator==(bigint a,bigint b){
	if(a.len!=b.len) return 0;
	for(int i=a.len;i>=1;i--) if(a[i]!=b[i]) return 0;
	return 1;
}
bool operator>(bigint a,bigint b){
	if(a.len>b.len) return 1;
	if(a.len<b.len) return 0;
	for(int i=a.len;i>=1;i--){
		if(a[i]>b[i]) return 1;
		if(a[i]<b[i]) return 0;
	}
	return 0;
}
bool operator<(bigint a,bigint b){
	if(a.len<b.len) return 1;
	if(a.len>b.len) return 0;
	for(int i=a.len;i>=1;i--){
		if(a[i]<b[i]) return 1;
		if(a[i]>b[i]) return 0;
	}
	return 0;
}
bool operator>=(bigint a,bigint b){return a<b?0:1;}
bool operator<=(bigint a,bigint b){return a>b?0:1;}
bool operator!=(bigint a,bigint b){return a==b?0:1;}
bigint operator+(bigint a,bigint b){
	bigint c;
	int len=max(a.len,b.len);
	for(int i=1;i<=len;i++) c[i]+=a[i]+b[i];
	c.f1(len+1);
	return c;
}
void operator+=(bigint &a,bigint b){a=a+b;}
void operator++(bigint &a){a=a+1;}
bigint operator-(bigint a,bigint b){
	bigint c;
	int l=max(a.len,b.len);
	for(int i=1;i<=l;i++) c[i]=a[i]-b[i];
	c.f2(l);
	return c;
}
void operator-=(bigint &a,bigint b){a=a-b;}
void operator--(bigint &a){a=a-1;}
bigint operator*(bigint a,bigint b){
	bigint c;
	for(int i=1;i<=a.len;i++)
		for(int j=1;j<=b.len;j++)
			c[i+j-1]+=a[i]*b[j];
	c.f1(a.len+b.len);
	return c;
}
void operator*=(bigint &a,bigint b){a=a*b;}
bigint operator/(bigint a,bigint b){
	bigint c,x;
	for(int i=a.len;i>=1;i--){
		x=x*10+a[i];
		while(x>=b) x-=b,c[i]++;
	}
	c.f1(a.len);
	return c;
}
void operator/=(bigint &a,bigint b){a=a/b;}
bigint operator%(bigint a,bigint b){return a-a/b*b;}
void operator%=(bigint &a,bigint b){a=a%b;}
int main(){
	bigint a,b;
	a.read();
	char c=getchar();
	b.read();
	if(c=='+'){
		(a+b).print();
		cout<<endl;
	}
	else{
		(a*b).print();
		cout<<endl;
	}
	return 0;
}
2022/11/17 13:55
加载中...