Cod sursa(job #2440140)

Utilizator daniknicolae dan danik Data 17 iulie 2019 17:01:49
Problema Next Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 4.75 kb
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX_DIGITS=1024;
const int BASE=10;
class HugeN
{
    private: int x[MAX_DIGITS];
    public: HugeN()
        {
        memset(x,0,sizeof(x));
        x[0]=1;
        }
      HugeN(int n)
      {
          memset(x,0,sizeof(x));
          do
          {
              ++x[0];
              x[x[0]]=n%10;
              n=n/10;
          }while(n>0);
      }
      HugeN(const HugeN&other)
      {
          memcpy(x,other.x,sizeof(other.x));
      }
      void print()
      {
          int i;
          for(i=x[0];i>=1;i--)
              cout<<x[i];
          cout<<"\n";
      }
     int cmp (const HugeN&other)
     {
      /* = devine 0
         < devine -1
         > devine 1   */
      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;
            }
     }
    bool operator < (const HugeN& other);
    bool operator <= (const HugeN& other);
    bool operator > (const HugeN& other);
    bool operator >= (const HugeN& other);
    bool operator == (const HugeN& other);
    bool operator != (const HugeN& other);
    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 += (const HugeN& other);
    HugeN operator -= (const HugeN& other);
    HugeN operator *= (int k);
    HugeN operator /= (int k);
    int operator %(int k);
};

 bool HugeN::operator < (const HugeN& other)
 {
     if((*this).cmp(other)==-1) return 1;
     return 0;
 }
 bool HugeN::operator <= (const HugeN& other)
 {
     if((*this).cmp(other)<=0) return 1;
     return 0;
 }
 bool HugeN::operator > (const HugeN& other)
 {
     if((*this).cmp(other)==1) return 1;
     return 0;
 }
 bool HugeN::operator >= (const HugeN& other)
 {
     if((*this).cmp(other)>=0) return 1;
     return 0;
 }
 bool HugeN::operator == (const HugeN& other)
 {
     if((*this).cmp(other)==0) return 1;
     return 0;
 }
 bool HugeN::operator != (const HugeN& other)
 {
     if((*this).cmp(other)!=0) return 1;
     return 0;
 }
HugeN HugeN::operator + (const HugeN& other)
{
    HugeN temp;
    int trecere=0,d;
    temp.x[0]=max(x[0],other.x[0]);
    for(int i=1;i<=temp.x[0];i++)
    {
        d=x[i]+other.x[i]+trecere;
        temp.x[i]=d%10;
        trecere=d/10;
    }
    if(trecere>0)
        temp.x[++temp.x[0]]=trecere;
    return temp;
}
HugeN HugeN::operator - (const HugeN& other)
{
    HugeN temp;
    int trecere=0,d;
    temp.x[0]=x[0];
    for(int i=1;i<=temp.x[0];i++)
    {
        d=x[i]-other.x[i]-trecere;
        if(d<0)
        {
            d=d+10;
            trecere=1;
        }
        else
            trecere=0;
        temp.x[i]=d;
    }
    while(temp.x[temp.x[0]]==0 && temp.x[0]>=1)
        temp.x[0]--;
    return temp;
}
HugeN HugeN::operator *= (int k)
{
    int tr=0,i,aux;
    for(i=1;i<=x[0];i++)
    {
        x[i]=x[i]*k;
    }
    for(i=1;i<=x[0];i++)
    {
        aux=x[i]+tr;
        x[i]=aux%10;
        tr=aux/10;
    }
    aux=x[0];
    while(tr)
    {
        aux++;
        x[aux]=tr%10;
        tr=tr/10;
    }
    x[0]=aux;
    return (*this);
}
HugeN HugeN::operator += (const HugeN& other)
{
  int i,t,k;
  x[0]=max(x[0],other.x[0]);
  for(t=0,i=1;i<=x[0];i++)
  {
      k=x[i]+other.x[i]+t;
      x[i]=k%10;
      t=k/10;
  }
  if(t)
  {
      x[0]++;
      x[x[0]]=t;
  }
  return (*this);
}
HugeN HugeN::operator * (const HugeN& other)
{
    HugeN c;
    int i,j,tr,k;
    c.x[0]=x[0]+other.x[0]-1;
    for(i=1;i<=x[0];i++)
        for(j=1;j<=other.x[0];j++)
        c.x[i+j-1]+=x[i]*other.x[j];
    tr=0;
    for(i=1;i<=c.x[0];i++)
    {
        k=c.x[i]+tr;
        c.x[i]=k%10;
        tr=k/10;
    }
    k=c.x[0];
    while(tr)
    {
        k++;
        c.x[k]=tr%10;
        tr=tr/10;
    }
    c.x[0]=k;
    return c;
    

}
/*HugeN HugeN::operator / (int k)
{

}*/
int main()
{
   
   int n,e,k,i;
   cin>>n;
    HugeN p(1);
    if(n%3==0)                                                                                                                                                                                                       
        e=n/3;
    else
        if(n%3==1)
        p*=4, e=n/3-1;
        else
            p*=2,e=n/3;
    k=3;
    for(i=1;i<=n;i++)
        p*=k;
    return 0;
  }