Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. const int ksize = 1000;
  6.  
  7. class Huge{
  8. public:
  9.     int a[ksize];
  10.  
  11.     void Reset(){
  12.         memset(a,0,sizeof(a));
  13.         a[0]=1;
  14.     }
  15.     Huge(){
  16.         Reset();
  17.     }
  18.  
  19.     void setValue(int x){
  20.         Reset();
  21.         a[0]=0;
  22.         do{
  23.             a[0]++;
  24.             a[a[0]] = x % 10;
  25.             x/=10;
  26.         }while(x);
  27.     }
  28.     void operator +=(const Huge &other){
  29.         int i, t= 0;
  30.         for(i = 1; i <= a[0] || i <= other.a[0] || t != 0;i++, t/=10)
  31.         {
  32.             a[i] = (t+= a[i] + other.a[i]) % 10;
  33.         }
  34.         a[0] = i - 1;
  35.     }
  36.  
  37.     void addInteger(int x)
  38.     {
  39.         int i, t= 0;
  40.         for(i = 1; i<= a[0] || x!=0 || t!= 0; i++, t/=10, x/=10)
  41.         {
  42.             a[i] = (t += a[i] + x % 10) % 10;
  43.         }
  44.         a[0] = i - 1;
  45.     }
  46.  
  47.     void printNumber()
  48.     {
  49.         int i;
  50.         for(i = a[0]; i >= 1; i--)
  51.             printf("%d",a[i]);
  52.     }
  53.  
  54.  
  55. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement