60求助

P1303 A*B Problem

__DIOsama__ @ 2023-10-02 09:30:01

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>

#define int long long
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define rop(a,b,c) for(int a=b;a<c;--a)
#define per(a,b,c) for(int a=b;a>=c;--a)

typedef long long ll;

class Sol {
private:
    std::vector<int> mul(std::vector<int>& A, int b) {
        std::vector<int> C;
        int t = 0;
        for (int i = 0; i<A.size() || t; i++) {
            if (i<A.size()) {
                t = A[i] * b + t;
            }
            C.push_back(t % 10);
            t/=10;
        }
        while (C.size() > 1 && C.back() == 0)  C.pop_back();
        if (t) C.push_back(t);
        return C;
    }
public:
    inline void sol() {
        std::string a;
        int b;
        std::vector<int> A;
        std::cin >> a >> b;
        for (int i=a.size() - 1; i >= 0; i --) A.push_back(a[i] - '0');
        auto C = mul(A, b);
        for (ll i=C.size()-1;i>=0;i--) printf("%lld",C[i]);

    } 

} T;

signed main() {
    T.sol(); 
    return 0;
}

|