提交记录 11218


用户 题目 状态 得分 用时 内存 语言 代码长度
_DAG_ 1004a. 【模板题】高精度乘法2 Accepted 100 57.025 ms 304 KB C++ 3.00 KB
提交时间 评测时间
2019-11-06 20:33:27 2020-08-01 02:40:15
#include<iostream>
#include<vector>
#include<cstring>

using namespace std;

struct Bigint:vector<int>
{
    Bigint(int x=0)
    {
        push_back(x);
        check();
    }
    Bigint& check()
    {
        while(!empty()&&!back()) pop_back();
        if(empty()) return *this;
        for(int i=1;i<size();++i)
        {
            (*this)[i]+=(*this)[i-1]/10;
            (*this)[i-1]%=10;
        }
        while(back()>=10)
        {
            push_back(back()/10);
            (*this)[size()-2]%=10;
        }
        return *this;
    }
};
istream& operator>>(istream &is,Bigint &x)
{
    string s;
    is>>s;
    x.clear();
    for(int i=s.size()-1;i>=0;--i) x.push_back(s[i]-'0');
    return is;
}
ostream& operator<<(ostream &os,const Bigint &x)
{
    if(x.empty()) os<<0;
    for(int i=x.size()-1;i>=0;--i) os<<x[i];
    return os;
}
bool operator!=(const Bigint &a,const Bigint &b)
{
    if(a.size()!=b.size()) return 1;
    for(int i=a.size()-1;i>=0;--i) if(a[i]!=b[i]) return 1;
    return 0;
}
bool operator==(const Bigint &a,const Bigint &b)
{
    return !(a!=b);
}
bool operator<(const Bigint &a,const Bigint &b)
{
    if(a.size()!=b.size()) return a.size()<b.size();
    for(int i=a.size()-1;i>=0;--i)
        if(a[i]!=b[i]) return a[i]<b[i];
    return 0;
}
bool operator>(const Bigint &a,const Bigint &b)
{
    return b<a;
}
bool operator<=(const Bigint &a,const Bigint &b)
{
    return !(a>b);
}
bool operator>=(const Bigint &a,const Bigint &b)
{
    return !(a<b);
}
Bigint& operator+=(Bigint &a,const Bigint &b)
{
    if(a.size()<b.size()) a.resize(b.size());
    for(int i=0;i!=b.size();++i) a[i]+=b[i];
    return a.check();
}
Bigint& operator+(Bigint a,const Bigint &b)
{
    return a+=b;
}
Bigint& operator-=(Bigint &a,Bigint b)
{
    if(a<b) swap(a,b);
    for(int i=0;i!=b.size();a[i]-=b[i],++i)
    {
        if(a[i]<b[i])
        {
            int j=i+1;
            while(!a[j]) ++j;
            while(j>i)
            {
                --a[j];
                a[--j]+=10;
            }
        }
    }
    return a.check();
}
Bigint operator-(Bigint a,const Bigint &b)
{
    return a-=b;
}
Bigint operator*(const Bigint &a,const Bigint &b)
{
    Bigint x;
    x.assign(a.size()+b.size()-1,0);
    for(int i=0;i!=a.size();++i)
        for(int j=0;j!=b.size();++j)
            x[i+j]+=a[i]*b[j];
    return x.check();
}
Bigint& operator*=(Bigint &a,const Bigint &b)
{
    return a=a*b;
}
Bigint divmod(Bigint &a,const Bigint &b)
{
    Bigint ans;
    for(int t=a.size()-b.size();a>=b;--t)
    {
        Bigint d;
        d.assign(t+1,0),d.back()=1;
        Bigint c=b*d;
        while(a>=c)
        {
            a-=c;
            ans+=d;
        }
    }
    return ans;
}
Bigint operator/(Bigint a,const Bigint &b)
{
    return divmod(a,b);
}
Bigint& operator/=(Bigint &a,const Bigint &b)
{
    return a=a/b;
}
Bigint& operator%=(Bigint &a,const Bigint &b)
{
    divmod(a,b);
    return a;
}
Bigint operator%(Bigint a,const Bigint &b)
{
    return a%=b;
}

int main()
{
    Bigint a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #157.025 ms304 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:16:25 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠