跳到正文

剪贴板

剪贴板 lpbtae32

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int len,num[4005];
    void clear() {len=1,memset(num,0,sizeof(num));}
    node &operator=(const string &s)
    {
        clear();len=s.size();
        for (int i=0;i<len;i++) num[len-i]=s[i]-'0';
        while(len>1&&!num[len]) len--;return *this;
    }
    node &operator=(long long s)
    {
        clear();for (int i=1;s;i++) num[i]=s%10,s/=10,len=i;
        return *this;
    }
    node friend operator+(const node &a,const node &b)
    {
        node ans;ans.clear();int x=0;
        while(ans.len<=a.len||ans.len<=b.len)
        {
            ans.num[ans.len]=a.num[ans.len]+b.num[ans.len]+x;
            x=ans.num[ans.len]/10,ans.num[ans.len]%=10,ans.len++;
        }
        ans.num[ans.len]=x;
        while(!ans.num[ans.len]&&ans.len>1) ans.len--;
        return ans;
    }
    node friend operator-(node &a,const node &b)
    {
        node ans;ans.clear();int i=1;
        while(i<=a.len||i<=b.len)
        {
            if (a.num[i]<b.num[i]) a.num[i]+=10,a.num[i+1]--;
            ans.num[i]=a.num[i]-b.num[i],i++;
        }
        while(!ans.num[ans.len]&&ans.len>1) ans.len--;
        return ans;
    }
    node friend operator*(const node &a,const node &b)
    {
        node ans;ans.clear();
        for (int i=1;i<=a.len;i++)
	    {
		    int x=0;
		    for (int j=1;j<=b.len;j++)
		    {
		    	ans.num[i+j-1]=a.num[i]*b.num[j]+x+ans.num[i+j-1];
		    	x=ans.num[i+j-1]/10,ans.num[i+j-1]%=10;
		    }
		    ans.num[i+b.len]=x;
	    }
	    ans.len=a.len+b.len;
	    while(!ans.num[ans.len]&&ans.len>1) ans.len--;
        return ans;
    }
    node friend operator/(const node &a,const int &b)
    {
        node ans;ans.clear();int x=0;
        for (int i=a.len;i;i--)
        {
            ans.num[i]=(x*10+a.num[i])/b;
            x=(x*10+a.num[i])%b;
        }
        ans.len=a.len;
        while(!ans.num[ans.len]&&ans.len>1) ans.len--;
        return ans;
    }
    friend bool operator<(const node &x,const node &y)
    {
        if (x.len<y.len) return true;
        if (x.len>y.len) return false;
        for (int i=x.len;i;i--)
        {
            if (x.num[i]>y.num[i]) return false;
            if (x.num[i]<y.num[i]) return true;
        }
        return false;
    }
    friend bool operator>(const node &x,const node &y) {return y<x;}
	friend bool operator<=(const node &x,const node &y) {return !(x>y);}
	friend bool operator>=(const node &x,const node &y) {return !(x<y);}
    friend bool operator==(const node &x,const node &y) {return !(x<y)&&!(y<x);}
    friend bool operator!=(const node &x,const node &y) {return (x<y)||(y<x);}
    node friend operator+=(node &a,const node &b) {return a=a+b;}
    node friend operator-=(node &a,const node &b) {return a=a-b;}
    node friend operator*=(node &a,const node &b) {return a=a*b;}
    node friend operator/=(node &a,const int &b) {return a=a/b;}
}a,b;
istream &operator>>(istream &in,node &x) {string s;cin>>s;x=s;return in;}
ostream &operator<<(ostream &out,const node &x)
{
    for (int i=x.len;i;i--) cout<<x.num[i];
    return out;
}