20分求助qwq

P1303 A*B Problem

wh0ever_ @ 2021-12-09 21:10:19

RT 代码如下

#include <bits/stdc++.h>
using namespace std;
int a[10010], b[10010], c[10010];
int ccin(int x[])
{
    string s;
    cin >> s;
    int len = s.size();
    for (int i = 0; i < len; i++)
    {
        x[i] = s[len - 1 - i] - '0';
    }
    return len;
}
int main()
{
    int i, j, y;
    int e1 = ccin(a), e2 = ccin(b);
    int k;
    for (i = 0; i < e1; i++)
    {
        for (j = 0; j < e2; j++)
        {
            k = a[i] * b[j] + c[i + j];
            c[i + j] = k % 10;
            c[i + j + 1] += k / 10;
        }
    }
    y = e1 + e2 - 1;
    while (!c[y] && y > 0)
        y--;
    for (i = y; i >= 0; i--)
    {
        cout << c[i];
    }
    return 0;
}

by EC75 @ 2021-12-15 19:24:00

@yyds严天翼 其实这题你如果有一点Python基础的话,用Python解是很简单的。

a=int(input())
b=int(input())
print(a*b)

我不会告诉你Python自带高精


by wry_QWQ @ 2021-12-25 09:29:28

STL大法好

#include<bits/stdc++.h>
using namespace std;
string a,b;
vector<int> mul(vector<int> &A, vector<int> &B) {
    vector<int> C(A.size()+B.size(),0);
    for (int i=0; i<A.size(); i++)
        for (int j=0; j<B.size(); j++)
            C[i+j]+=A[i]*B[j];
    int t=0;
    for (int i=0; i<C.size(); i++) {
        t+=C[i];
        C[i]=t%10;
        t/=10;
    }
    while (C.size()>1 && C.back()==0)
        C.pop_back();
    return C;
}

int main() {
    cin>>a>>b;
    vector<int> A,B;
    for (int i=a.size()-1; i>=0; i--)
        A.push_back(a[i]-'0');
    for (int i=b.size()-1; i>=0; i--)
        B.push_back(b[i]-'0');
    auto C=mul(A,B);
    for (int i=C.size()-1; i>=0; i--)
        cout<<C[i];
    return 0;
}

by Lovely_day @ 2022-01-01 11:14:18

不是对的吗 记录


|