Advertisement
Morass

BigInt

Mar 4th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. struct big{
  2.     static const long long MX=999999999;
  3.     long long l,a[1024];
  4.     big(int A=0):l(1){a[0]=A;}
  5.     bool eq(int h){return l==1&&a[0]==h;}
  6.     void operator=(int h){
  7.         a[0]=h;
  8.         l=1;
  9.     }/*Care - if used on itself, remove '&'!*/
  10.     void operator+=(big &b){
  11.         for(int i(0);i<b.l;++i)
  12.             add(b.a[i],i);
  13.     }
  14.     void add(long long s,int nd){
  15.         if(nd==l)
  16.             a[l++]=0;
  17.         a[nd]+=s;
  18.         if(a[nd]>MX)
  19.             a[nd]-=MX+1,add(1,nd+1);
  20.     }
  21.     void prt(void){
  22.         printf("%lld",a[l-1]);
  23.         for(int i(l-2);~i;--i)
  24.             printf("%09lld",a[i]);
  25.     }
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement