1 , 4 , 5WA 求助

P1303 A*B Problem

lnwwr @ 2020-08-09 12:10:08

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string num1, num2;
int a1[105], a2[105], len1, len2, a[205], len;
int main() {
    cin >> num1 >> num2;
    len1 = num1.size();
    for (int i = 0; i < len1; i++) {
        a1[i] = num1[len1 - 1 - i] - '0';
    }
    len2 = num2.size();
    for (int i = 0; i < len2; i++) {
        a2[i] = num2[len2 - 1 - i] - '0';
    }
    for(int i=0;i<len1;i++)
    {
        for(int j=0;j<len2;j++)
        {
            a[i+j]+=a1[i]*a2[j];
        }
    }
    len=len1+len2-1;
    for (int i = 0; i < len; i++) {
        a[i + 1] += a[i] / 10;
        a[i] %= 10;
    }
    while (a[len]) {
        a[len + 1] += a[len] / 10;
        a[len] %= 10;
        len++;
    }
    for (int i = len - 1; i >= 0; i--) {
        cout << a[i];
    }
    cout << endl;
    return 0;
}

by _OAIM_ @ 2020-08-09 12:55:53

楼主可以参考:高精度计算


by lnwwr @ 2020-08-09 14:39:45

@oamoam 谢谢


by liweiqing @ 2021-01-10 17:14:30

数组开大点

char a[2001],b[2001];
int aa[2001],bb[2001],ans[4002];

|