提交记录 20816


用户 题目 状态 得分 用时 内存 语言 代码长度
xuziyi 1004. 【模板题】高精度乘法 Runtime Error 0 10.664 ms 2992 KB C++ 1.76 KB
提交时间 评测时间
2024-01-20 00:41:32 2024-01-20 00:41:35
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std; 
const int mx=4e3+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[20];
		sprintf(str,"%d",x);
		return *this=str;
	}
	bign operator =(const char *num){//高精度=字符串 
		memset(s,0,sizeof(s));
		l=strlen(num);
		for(int i=1; i<=l; i++) s[i]=num[l-i]-'0';
		return *this;
	}
	bign operator +(bign b){//高精度+高精度 
		bign c;
		int len=l>b.l?l:b.l;
		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 - (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 *(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;
	}
	bool operator >(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 <(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 ==(bign b){
	    return !(*this>b) && !(*this<b);
	}
	bool operator >=(bign b){
	    return (*this>b) || (*this==b);
	}
	void clean(){//清除最高位0 
		while(l>1&&s[l]==0) l--;
	}
};
istream& operator >>(istream&in, bign &x){
	string str;
	in>>str;
	x=str.c_str();
	return in;
}
ostream& operator <<(ostream&out,const  bign x){
	 for(int i=x.l; i>=1; i--) out<<x.s[i];
	 return out;
}
int main(){ 
	bign a,b;
	cin>>a>>b;
        cout<<a*b;
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #110.664 ms2 MB + 944 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2025-07-23 08:32:04 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠