Cod sursa(job #1284595)

Utilizator bciobanuBogdan Ciobanu bciobanu Data 6 decembrie 2014 17:17:57
Problema Next Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.7 kb
#include <cstdio>
#include <cstring>
#include <cctype>

#define IN "next.in"
#define OUT "next.out"
#define MAX 1000005

using namespace std;
class HUGE
{
private:
    int x[MAX];
public:
    HUGE()
    {
        memset(x, 0, sizeof(x));
        *x = 1;
    }
    void operator =(const char s[])
    {
        memset(x, 0, sizeof(x));
        int i = strlen(s) - 2;
        do
        {
            x[++*x] = s[i] - '0';
            --i;
        }
        while(i >= 0);
    }
    void operator +=(int a)
    {
        int i = 1, t = 0;
        do
        {
            t = t + x[i] + a % 10;
            x[i] = t % 10;
            t /= 10;
            a /= 10;
            ++i;
        }
        while(a);
        if(t)
        {
            while(x[i] + t > 9)
                ++i;
            if(i > x[0])
                x[++*x] = t;
            else
                x[i] = x[i] + t;
        }
    }
    long long operator %(const long long &MOD)
    {
        long long r = 0;
        int i;
        for(i = *x; i; --i)
            r = ((r << 1) + (r << 3) + x[i]) % MOD;
        return r;
    }
    void print(FILE *out = stdout)
    {
        for(int i = *x; i; --i)
            fprintf(out, "%d", x[i]);
    }
};
FILE *in, *out;
HUGE M;
char aux[MAX];
long long d, l;
void citire()
{
    in = fopen(IN, "r");
    fgets(aux, MAX, in);
    M = aux;
    fscanf(in, "%lld", &d);
    fclose(in);
}
void rezolvare()
{
    l = M % d;
    if(l)
        M += (d - l);
}
void afisare()
{
    out = fopen(OUT, "w");
    M.print(out);
    fputc('\n', out);
    fclose(out);
}
int main()
{
    citire();
    rezolvare();
    afisare();
    return 0;
}