主要用string 实现
#include<bits/stdc++.h>
using namespace std;
string mult(string a,int b){
string p="";
int carry=0;
reverse(a.begin(),a.end());
for(int i=0;i<a.size();i++){
int temp=(a[i]-'0')*b;
p+=carry+temp%10+'0';
carry=temp/10;
}
if(carry!=0) p+=carry+'0';
reverse(p.begin(),p.end());
return p;
}
string mults(string a,string b){
int n[200]={};
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
int len=a.size()+b.size()-1;
for(int i=0;i<a.size();i++){
for(int j=0;j<b.size();j++){
n[i + j] += (a[i]-'0') * (b[j]-'0');
}
}
for(int i=0;i<len;i++){
int temp=n[i];
n[i+1]+=temp/10;
n[i]=temp%10;
}
if(n[len]!=0)len++;
string s="";
cout<<len<<endl;
for(int i=len-1;i>=0;i--){
s+=to_string(n[i]);//倒着加 不需要考虑最后一位存的多位数
//cout<<n[i];
}
//reverse(s.begin(),s.end());
return s;
}
string adds( string a, string b){
string s="";
int jw=0,i=a.size()-1,j=b.size()-1;
while(i>=0||j>=0||jw>0){
int numa=i>=0?a[i--]-'0':0;
int numb=j>=0?b[j--]-'0':0;
int temp=numa+numb+jw;
s+=temp%10+'0';
jw=temp/10;
}
reverse(s.begin(),s.end());
return s;
}
int main(){
string a("123456789");
string b("123");
string c=mults(a,b);
cout<<c;
}