提交记录 19110


用户 题目 状态 得分 用时 内存 语言 代码长度
02Ljh 1004a. 【模板题】高精度乘法2 Accepted 100 59.071 ms 436 KB C++ 5.83 KB
提交时间 评测时间
2023-02-06 10:16:37 2023-02-06 10:16:40
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll gg
#define MAXN 100019
#define WA puts("CCF");
struct gg
{
    vector<int> q;
    bool op;//-F +T
    int len;
};
gg operator -(gg a_,gg b_);
gg operator +(gg a_,gg b_);
gg operator *(gg a_,gg b_);
gg operator /(gg a_,gg b_);
gg operator %(gg a_,gg b_);
bool operator <(gg a_,gg b_);
bool operator >(gg a_,gg b_);
bool operator ==(gg a_,gg b_);
gg in();
gg int_to_gg(int a_);
gg max_g(gg a_,gg b_);
gg min_g(gg a_,gg b_);
void out(gg a_);
void pr(vector<int> q){puts("\nAC:");for(auto i:q){cout<<i<<" ";}puts("\nAC\n");}
int main()
{
    gg a=in();
    //getchar();
    gg b=in();
    out(a*b);
    return 0;
}
gg int_to_gg(int a_)
{
    if(a_==0)
    {
        gg fore;
        fore.q.push_back(0);
        fore.op=false;
        fore.len=fore.q.size();
        return fore;
    }
    gg new_;
    new_.op=false;
    new_.q.clear();
    if(a_<0)
    {
        a_=-a_;
        new_.op=true;
    }
    while(a_>0)
    {
        //cout<<a_<<"\n";
        new_.q.push_back(a_%10);
        a_/=10;
    }
    new_.len=new_.q.size();
    return new_;
}
void out(gg a_)
{
    if(a_.op) cout<<"-";
    for(int i=a_.len-1;i>=0;i--)
    {
        cout<<a_.q[i];
    }
    return ;
}
gg operator -(gg a_,gg b_)//t - f +
{
    bool ne_=false;
    if(a_.op&&b_.op) ne_=false;//a>0 b>0
    else if(!a_.op&&b_.op)//a>0 b<0
    {
        b_.op=false;
        return b_+a_;
    }
    else if(a_.op&&!b_.op)//a<0 b>0
    {
        a_.op=false;
        return a_+b_;
    }
    else if(!a_.op&&!b_.op) ne_=false;//a<0 b<0
    if(a_<b_) { ne_=true; swap(a_,b_); }//-
    int l_len=min(a_.len,b_.len);
    if(b_.len>a_.len) swap(a_,b_);
    for(int i=0;i<a_.len;i++)
    {
        if(i<l_len) a_.q[i]-=b_.q[i];
        if(a_.q[i]<0)
        {
            a_.q[i]+=10;
            if(i+1==a_.len) ne_=true;//-
            else a_.q[i+1]-=1;
        }
    }
    while(!a_.q.empty())
    {
        if(a_.q.back()==0) a_.q.pop_back();
        else break;
    }
    a_.op=ne_;
    if(a_.q.empty()) { a_.op=false; a_.q.push_back(0); }
    a_.len=a_.q.size();
    return a_;
}
gg operator +(gg a_,gg b_)
{
    bool ne_=false;//T - F +
    if(!a_.op&&!b_.op) ne_=false;//a,b>0
    else if(!a_.op&&b_.op)//a>0 b<0
    {
        b_.op=false;
        return a_-b_;
    }
    else if(a_.op&&!b_.op)//a<0 b>0
    {
        a_.op=false;
        return b_-a_;
    }
    else if(!a_.op&&!b_.op) ne_=false; //a<0 b<0
    int l_len=min(a_.len,b_.len);
    if(b_.len>a_.len) swap(a_,b_);
    a_.op=ne_;
    for(int i=0;i<a_.len;i++)
    {
        if(i<l_len) a_.q[i]+=b_.q[i];
        if(a_.q[i]>=10)
        {
            a_.q[i]%=10;
            if(i+1==a_.len) a_.q.push_back(1);
            else a_.q[i+1]+=1;
        }
    }
    a_.len=a_.q.size();
    return a_;
}
gg operator *(gg a_,gg b_)//T - F +
{
	bool ne=false;
    if(a_.op!=b_.op)
    {
        ne=true;
    }
    gg new_;
    new_.op=ne;
    for(int i=0;i<2*max(a_.len,b_.len)+19;i++)
    {
        new_.q.push_back(0);
    }
    for(int i=0;i<b_.len;i++)
    {
        for(int j=0;j<a_.len;j++)
        {
            new_.q[i+j]+=b_.q[i]*a_.q[j];
        }
    }
    for(int i=0;i<new_.q.size();i++)
    {
        new_.q[i+1]+=new_.q[i]/10;
        new_.q[i]%=10;
    }
    while(!new_.q.empty())
    {
        if(new_.q.back()==0) new_.q.pop_back();
        else break;
    }
    if(new_.q.empty()) new_.q.push_back(0);
    new_.len=new_.q.size();
    return new_;
}
gg operator /(gg a_,gg b_)
{
    if(a_<b_) return (int_to_gg(0));
    if(a_==b_) return (int_to_gg(1));
    bool ne=false;
    if(a_.op!=b_.op)
    {
        ne=true;
    }
    gg new_;
    new_.op=ne;
    new_.q.clear();
    vector<int> temp;
    temp.clear();
    gg st=int_to_gg(0);
    for(int i=a_.len-1;i>=0;i--)
    {
        st=st+int_to_gg(a_.q[i]);
        if(st>b_||st==b_)
        {
            int ans_=0;
            while(st>b_||st==b_)
            {
                st=st-b_;
                ans_++;
            }
            /*if(st==b_)
            {
                st=int_to_gg(0);
                ans_++;
            }*/
            temp.push_back(ans_);
        }
        else
        {
            temp.push_back(0);
            //WA;
        }
        st=st*int_to_gg(10);
    }
    while(!temp.empty())
    {
        new_.q.push_back(temp.back());
        temp.pop_back();
    }
    while(!new_.q.empty())
    {
        if(new_.q.back()==0) new_.q.pop_back();
        else break;
    }
    if(new_.q.empty()) new_.q.push_back(0);
    new_.len=new_.q.size();
    return new_;
}
gg operator %(gg a_,gg b_)
{
    gg tem=a_/b_;
    gg temp=tem*b_;
    return a_-temp;
}
gg in()
{
    char a_;
    gg new_;
    new_.q.clear();
    //.ignore();
    a_=getchar();
    //cout<<a_;
    if(a_=='\n') a_=getchar();
    //cout<<a_;
    new_.op=false;
    if(a_=='-')
    {
        a_=getchar();
        new_.op=true;
    }
    vector<int> q_new;
    q_new.clear();
    while(a_>='0'&&a_<='9')
    {
        q_new.push_back((int)(a_-'0'));
        a_=getchar();
    }
    //for(auto i:q_new) cout<<i;
    while(!q_new.empty())
    {
        new_.q.push_back(q_new.back());
        q_new.pop_back();
    }
    new_.len=new_.q.size();
    //WA;
    return new_;
}
bool operator <(gg a_,gg b_)//T -F +
{
    if(a_.len==b_.len)
    {
        for(int i=b_.len-1;i>=0;i--)
        {
            if(a_.q[i]==b_.q[i]) continue;
            else return a_.q[i]<b_.q[i];
        }
        return false;
    }
    else return a_.len<b_.len;
}
bool operator ==(gg a_,gg b_)
{
    if(a_.len==b_.len)
    {
        for(int i=a_.len-1;i>=0;i--)
        {
            if(a_.q[i]!=b_.q[i]) return false;
        }
        return true;
    }
    else return false;
}
bool operator >(gg a_,gg b_)
{
    if(a_<b_||a_==b_) return false;
    else return true;
}
gg max_g(gg a_,gg b_)
{
    if(a_<b_) return b_;
    else return a_;
}
gg min_g(gg a_,gg b_)
{
    if(a_<b_) return a_;
    else return b_;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #159.071 ms436 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-05 10:47:18 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用