Cod sursa(job #957841)

Utilizator visanrVisan Radu visanr Data 6 iunie 2013 09:42:55
Problema A+B Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.51 kb
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

#define DigitMax 100

class Huge
{
    public: int V[DigitMax];
    Huge ()
    {
        memset(V, 0, sizeof(V));
    }
    Huge (int X)
    {
        *this = X;
    }

    Huge operator= (int X)
    {
        memset(V, 0, sizeof(V));
        for(; X; X /= 10)
            V[++V[0]] = X % 10;
        return *this;
    }
    Huge operator= (Huge X)
    {
        memcpy(V, X.V, sizeof(X.V));
        return *this;
    }

    Huge operator+ (Huge X) const
    {
        int i, T = 0;
        Huge Now;
        for(i = 1; i <= V[0] || i <= X.V[0] || T; i++, T /= 10)
            Now.V[i] = (T += V[i] + X.V[i]) % 10;
        Now.V[0] = i - 1;
        return Now;
    }
    Huge operator+ (int X) const
    {
        return *this + Huge(X);
    }

    Huge operator* (Huge X) const
    {
        Huge Now;
        int i, j, T = 0;
        for(i = 1; i <= V[0]; i ++)
        {
            for(j = 1, T = 0; j <= X.V[0] || T; j ++, T /= 10)
                Now.V[i + j - 1] = (T += Now.V[i + j - 1] + V[i] * X.V[j]) % 10;
            if(i + j - 2 >= Now.V[0]) Now.V[0] = i + j - 2;
        }
        return Now;
    }
    Huge operator* (int X) const
    {
        return *this * Huge(X);
    }

    Huge operator- (Huge X) const
    {
        Huge Now;
        Now = *this;
        int i, T = 0;
        for(i = 1; i <= V[0]; i ++)
        {
            Now.V[i] -= (i <= X.V[0] ? X.V[i] : 0) + T;
            Now.V[i] += (T = Now.V[i] < 0) * 10;
        }
        for(; Now.V[0] > 1 && !Now.V[Now.V[0]]; Now.V[0] --);
        return Now;
    }
    Huge operator- (int X) const
    {
        return *this - Huge(X);
    }

    Huge operator/ (int X) const
    {
        int i, T = 0;
        Huge Now = *this;
        for(i = Now.V[0]; i; i--, T %= X)
            Now.V[i] = (T = T * 10 + Now.V[i]) / X;
        for(; Now.V[0] > 1 && Now.V[Now.V[0]] == 0; Now.V[0] --);
        return Now;
    }

    int operator% (int X) const
    {
        int i, T = 0;
        for(i = V[0]; i; i--)
            T = (T * 10 + V[i]) % X;
        return T;
    }

    void Print() const
    {
        for(int i = V[0]; i; i--) printf("%d", V[i]);
        printf("\n");
    }
};

Huge A, B;

int main()
{
    int X, Y;
    freopen("adunare.in", "r", stdin);
    freopen("adunare.out", "w", stdout);
    scanf("%i %i", &X, &Y);
    printf("%i\n", X + Y);
    return 0;
}