1 条题解

  • 0

    典型的会一题吃所有
    #include<iostream>
    #define N 100010
    using namespace std;
    int a[N], b[N];
    inline int Mul(int a[], int lena, int b[], int lenb)
    { //和前几题一样的高精度板子
    int c[N] = { 0 };
    int lenc = lena + lenb;
    for (int i = 0; i < lena; i++)
    {
    for (int j = 0; j < lenb; j++)
    {
    c[i + j] += a[i] * b[j];
    c[i + j + 1] += c[i + j] / 10;
    c[i + j] %= 10;
    }
    }
    if (c[lenc-1] == 0 && lenc > 0)
    lenc--;
    for (int i = 0; i < lenc; i++)
    a[i] = c[i];
    return lenc;
    }
    inline int Input(int x[],int y[],int m,int n,int res[])
    { //封装输入函数并返回高精度乘法处理后的数组长度,将结果存在res1/2数组中
    int len, lena;
    int i = 0;
    while (m != 0)
    {
    x[i] = m % 10;
    y[i] = m % 10;
    m /= 10;
    i++;
    }
    len = lena = i;
    for (int i = 1; i < n; i++)
    lena = Mul(a,lena,b,len);
    for (int i = 0; i < lena; i++)
    res[i] = a[i];
    return lena;
    }
    int res1[N],res2[N],res[N];
    inline int Count(int x[],int y[],int len1,int len2)
    { //高精度加法板子,返回结果数组长度并将结果存在res数组中
    int c[N] = {0},len = max(len1,len2);
    for (int i = 0; i <= len; i++)
    {
    res[i] = x[i] + y[i] + c[i];
    if(res[i] > 9)
    {
    c[i+1] = res[i] / 10;
    res[i] %= 10;
    }
    }
    while (res[len] != 0)
    len++;
    return len;
    }
    int main()
    {
    int x1, n1, x2, n2;
    int len1,len2,len;
    cin >> x1 >> n1 >> x2 >> n2;
    len1 = Input(a,b,x1,n1,res1);
    len2 = Input(a,b,x2,n2,res2);
    len = Count(res1,res2,len1,len2);
    for (int i = len-1; i >= 0; i--)
    cout << res[i]; //反向输出结果
    return 0;
    }

  • 1

信息

难度
6
分类
(无)
标签
递交数
500
已通过
128
通过率
26%
被复制
8
上传者