高精度乘法 模板
1.char 类
void High_Char(char a[], char b[]) {
int num[500];
memset(num, 0, sizeof(num));
int l = strlen(a) + strlen(b);
int la = strlen(a);
int lb = strlen(b);
int sum;
for(int i=lb-1; i>=0; --i) {
for(int j=la-1,int k=i+j+1; j>=0; --j,--k) {
sum = (b[i]-'0') * (a[j]-'0') + num[k];
num[k] = sum%10;
num[k-1] += sum/10;
}
}
int i=num[0]?0:1;
for(int j=0; i<l; i++) {
a[j++] = (num[i]+'0');
a[j] = 0;
}
}
2. string 类
void HighString(string &a, string &b) {
int num[500];
memset(num, 0, sizeof(num));
int l = strlen(a) + strlen(b);
int la = strlen(a);
int lb = strlen(b);
int sum;
for(int i=lb-1; i>=0; --i) {
for(int j=la-1;int k=i+j+1; j>=0; --j,--k) {
sum = (b[i]-'0') * (a[j]-'0') + num[k];
num[k] = sum%10;
num[k-1] += sum/10;
}
}
int i = num[0]?0:1;
while(a.length() < l-i){
a = a+'0';
}
for(int j=0; i<l; i++) {
a[j++] = (num[i]+'0');
}
}