[else] operator

存一波重载运算符

只包含加,减,乘,还有快速幂。。

压位代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 10000
struct overload{
    ll a[5000];
    overload(){memset(a,0,sizeof a);}
    overload(int A){
        memset(a,0,sizeof(a));
        int tot=1;
        while(A){
            a[tot++]=A%maxn;
            A/=maxn;
        }
    }
    friend inline void read(overload&b){
        ll stack[10001],top=0,tot=1,t=0;
        char c=getchar();
//        if(c<=47||c>=58){
//            d=c;
//            return;
//        }
        while(c>='0'&&c<='9'){
            stack[top++]=c-48;
            c=getchar();
        }
        top--;
        while(top!=-1){
            if(top-8>=0){
                int base=top-8;
                while(t!=9&&top){
                    b.a[tot]=b.a[tot]*10+stack[base];
                    t++;
                    base++;
                }
                top-=9;
            }
            else{
                int i=0;
                while(i!=(top+1)){
                    b.a[tot]=b.a[tot]*10+stack[i];
                    i++;
                }
                top=-1;
            }
            //printf("%lld\n",b.a[tot]);
            tot++;
            t=0;
        }
    }
    friend inline void print(const overload&b){
        bool flag=false;
        for(int tot=4000;tot>0;tot--){
            if(flag) printf("%04lld",b.a[tot]);
            else {
            if(b.a[tot]) flag=true,printf("%lld",b.a[tot]);}
        }
        if(!flag) printf("0");
    //    putchar(10);
    //    printf("m:%d\n",m);
    }
    inline overload operator-(overload&b){
        overload c=*this;
        for(int i=1;i<=1000;i++){
            if(c.a[i]-b.a[i]<0){
                c.a[i+1]--;
                c.a[i]=maxn+c.a[i]-b.a[i];
            }
            else c.a[i]=c.a[i]-b.a[i];
        }
        return c;
    }
    inline overload operator+(overload&b){
        overload c=b;
        for(int i=1;i<=1000;i++){
            c.a[i]+=a[i];
            c.a[i+1]+=c.a[i]/maxn;
            c.a[i]%=maxn;
        }
        return c;
    }
    inline overload operator*(overload&b){
        overload p;
        for(int i=1;i<=2500;i++){
            if(a[i]!=0) {
                for(int j=1;j<=2500;j++){
                    if((p.a[j+i-1]+=a[i]*b.a[j])>(maxn-1)) {
                        p.a[j+i]+=p.a[j+i-1]/maxn;
                        p.a[j+i-1]=p.a[j+i-1]%maxn;
                    }
                }
            }
        }
        return p;
    }

    inline overload operator^(overload p){
        int n=p.a[1];
        overload base(*this),ans(1); 
        while(n){
            if(n&1) ans=ans*base;
            base=base*base;
            n=n/2;
        }
        return ans;
    }
};
int main(){
    overload  c,b,d,a;
//    int b;
    read(b);
    read(c);
    read(d);
    read(a);
    print(c+b);
    print(c*b);
    print(b-c);          
    print((b+c)^(a-d));
    
    return 0;
}
operator

 

posted @ 2018-01-29 20:50  Konnyaku  阅读(175)  评论(0编辑  收藏  举报