AC

元梦  •  1年前


include<bits/stdc++.h>

using namespace std; string Mul(string left,string right){

size_t Lsize=left.size();
size_t Rsize=right.size();
size_t Size=Lsize+Rsize;
string res(Size,'0');
int carry=0,offset=0;
size_t idx,j;
for(idx=1;idx<=Rsize;idx++){
	carry=0;
	int rightNum=right[Rsize-idx]-'0';
	for(j=1;j<=Lsize;j++){
		int resChar=res[Size-j-offset]-'0';
		int num=rightNum*(left[Lsize-j]-'0')+carry+resChar;
		carry=num/10;
		res[Size-j-offset]=num%10+'0';
	}
	if(carry) res[Size-j-offset]+=carry;
	offset++;
}
if(res[0]=='0') res.erase(0,1);
return res;

} int main(){

string a,b;
cin>>a>>b;
cout<<Mul(a,b)<<endl;
return 0;

}


评论:

请先登录,才能进行评论