Cod sursa(job #1518644)

Utilizator rares96cheseliRares Cheseli rares96cheseli Data 6 noiembrie 2015 01:18:46
Problema A+B Scor 0
Compilator cpp Status done
Runda Lista lui wefgef Marime 2.48 kb
#include <fstream>
#include <iostream>
#include <cstring>
#define Nmax 9050
using namespace std;
ifstream f("gigel.in");
ofstream g("gigel.out");

typedef short huge[Nmax];

void tohuge(long long X,huge A) { A[0]=0; while(X)A[++A[0]]=X % 10,X/=10; }

void tonumber(huge A,long long &X) { for(short i=A[0]; i>=1; --i)X=X*10+A[i];}

void read(huge A)
{
     char S[Nmax]; f>>S;
     for(short i=strlen(S)-1;i>=0;--i)A[++A[0]]=(S[i]-'0');
}

void show(huge A) { for(short i=A[0]; i>=1; --i)g<<A[i];g<<'\n'; }

void cpy(huge A,huge B) { B[0]=A[0]; for(short i=1;i<=A[0];++i)B[i]=A[i]; }

void delzero(huge A){ for(;A[0]>1 && !A[A[0]];--A[0]); }

short cmp(huge A,huge B)
{
    if(A[0]<B[0])return -1;//A-B<0
    if(A[0]>B[0])return 1; //A-B>0
    for(short i=A[0];i;--i)
        if(A[i]!=B[i])
        {
            if(A[i]<B[i])return -1;
                else return 1;
        }
    return 0; //A-B==0
}

void add(huge A, huge B, huge C)//C=A+B
{
    huge aux; short i,t=0;
    for(i=1; i<=A[0] || i<=B[0] || t; ++i,t/=10) aux[i]=(t+=A[i]+B[i])%10;
    aux[0]=--i; cpy(aux,C);
}

void diff(huge A,huge B,huge C)//C=A-B
{
    huge aux; short t=0;
    for(short i=B[0]+1; i<=A[0];++i)B[i]=0;
    for(short i=1;i<=A[0];++i)
    {
        aux[i]=A[i]-B[i]+t;
        if(aux[i]<0)aux[i]+=10,t=-1;
            else t=0;
    }
    aux[0]=A[0]; delzero(aux); cpy(aux,C);
}

void prodhuge(huge A,huge B,huge C)//C=AxB
{
    huge aux; short k=0;
    for(short i=0;i<=A[0]+B[0]+1;++i)aux[i]=0;
    for(short i=1;i<=B[0];++i,++k)
    {
         short t=0;
         for(short j=1;j<=A[0] || t;++j,t/=10)
              aux[j+k]=(t+=aux[j+k]+A[j]*B[i])%10;
    }
    aux[0]=A[0]+B[0]+1; delzero(aux); cpy(aux,C);
}

void exploghuge(huge N,short K)
{
    huge M; memset(M,0,sizeof(M)); M[++M[0]]=1;
    while(K!=1)
        if(K%2==0)prodhuge(N,N,N),K/=2;
            else prodhuge(M,N,M),--K;
    prodhuge(N,M,N);
}

void hugeXnumber(huge A,int b,huge C)//C=bA
{
    huge aux; short i,t=0;
    for (i=1; i<=A[0] || t; ++i,t/=10)
        aux[i]=(t += A[i]*b)%10;
    aux[0]=i-1; cpy(aux,C);
}

void div(huge A,int B,huge C)
{
    huge aux; int t=0;
    for(int i=A[0]; i>=1 ; --i,t%=B)
        aux[i]=(t=t*10+A[i])/B;
    aux[0]=A[0]; delzero(aux); cpy(aux,C);
}

long long MOD(huge A,long long B)
{
    long long t=0;
    for(int i=A[0];i>=1;--i)
        t=(t*10+A[i])% B;
    return t;
}

huge A,B,C; long long X;

int main()
{
     return 0;
}