51nod 1027 大数乘法

给出2个大整数A,B,计算A*B的结果。
 

输入

第1行:大数A
第2行:大数B
(A,B的长度 <= 1000,A,B >= 0)

输出

输出A * B

输入样例

123456
234567

输出样例

28958703552
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 50000
#define DMAX 10000
using namespace std;
typedef long long ll;
char a[1005],b[1005];
char ans[2005];
int main() {
    scanf("%s%s",a,b);
    int d = 0,alen = strlen(a),blen = strlen(b);
    for(int i = 0;a[i];i ++) {
        for(int j = 0;b[j];j ++) {
            d += (a[alen - 1 - i] - '0') * (b[blen - 1 - j] - '0');
            if(ans[i + j]) d += ans[i + j] - '0';
            ans[i + j] = d % 10 + '0';
            d /= 10;
        }
        if(d) {
            ans[i + blen] = d + '0';
            d = 0;
        }
    }
    reverse(ans,ans + strlen(ans));
    printf("%s",ans);
}
原文地址:https://www.cnblogs.com/8023spz/p/10055827.html