Cod sursa(job #1748298)

Utilizator MarutBrabete Marius Stelian Marut Data 26 august 2016 12:05:05
Problema Next Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.53 kb
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define NMAX 1<<10
class HugeN
{
    private: int x[NMAX];
    //constructori
    public: HugeN();
            HugeN(int nr);
            HugeN(const HugeN&other);
    //afisare nr
            void get_huge()
            {
                for(int i=x[0];i>=1;--i)
                    printf("%d",x[i]);
                printf("\n");
            }
    //Operatori aritmetici
    HugeN&operator + (const HugeN&other);
    HugeN&operator - (const HugeN&other);
    HugeN&operator * (const HugeN&other);
    HugeN&operator * (int k);
    HugeN&operator % (int k);
    HugeN&operator / (int k);
    // Functia de comparare
    int cmp(const HugeN&other);
};
HugeN::HugeN()
{
    memset(x,0,sizeof(x));
    x[0]=1;
}
HugeN::HugeN(int nr)
{
    memset(x,0,sizeof(x));
    do
    {
        x[++x[0]]=nr%10;
        nr=nr/10;
    }
    while(nr);
}
HugeN::HugeN(const HugeN&other)
{
    memcpy(x,other.x, sizeof(other.x));
}
int HugeN::cmp(const HugeN&other)
{
    //0 daca x==other
    //1 x>other
    // -1 x<other
    if(x[0]<other.x[0]) return -1;
        else if(x[0]>other.x[0]) return 1;
            else
            {
                for(int i=x[0];i>=1;--i)
                {
                    if(x[i]>other.x[i]) return 1;
                        else if(x[i]< other.x[i]) return -1;
                }
                return 0;
            }
}
HugeN& HugeN::operator - (const HugeN&other)
{
    // c=a+b    a=x b=other x  c=temp
    HugeN temp;
    temp.x[0]=max(x[0],other.x[0]);
    int i,tr,aux;
    tr=0;
    for(i=1;i<=temp.x[0];i++)
      {
        aux=x[i]-other.x[i]+tr;
        if(aux<0)
        {
            aux=aux+10;
            tr=-1;
        }
        temp.x[i]=aux;
    }
    return temp;
}
HugeN& HugeN::operator % (int k)
{
    int r=0,i;
    for(i=x[0];i>=1;--i)
    {
        r=r*10+x[i];
        r=r%k;
    }
    return r;
}
HugeN& HugeN::operator + (const HugeN&other)
{
    // c=a+b    a=x b=other x  c=temp
    HugeN temp;
    temp.x[0]=max(x[0],other.x[0]);
    int i,tr,aux;
    tr=0;
    for(i=1;i<=temp.x[0];i++)
      {
        aux=x[i]+other.x[i]+tr;
        temp.x[i]=aux%10;
        tr=aux/10;
    }
    if(tr!=0)
    {
        temp.x[0]++;
        temp.x[temp.x[0]]=tr;
    }
    return temp;
}
int main()
{
  long long d;
  HugeN (int c);
  scanf("%d",&d);
  HugeN a;
  HugeN b;
  HugeN l;
  a=c%d;
  b=d-a;
  l=c+b;
  c.get_huge();
  return 0;
}