Cod sursa(job #1239731)

Utilizator killer301Ioan Andrei Nicolae killer301 Data 9 octombrie 2014 17:54:30
Problema Next Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.91 kb
#include <cstdio>
#include <cstring>

using namespace std;

class HN
{
private:
    char x[1000005];
public:
    HN()
    {
        memset(x, 0, sizeof(x));
        x[0]=1;
    }
    /*HN(int n)
    {
        memset(x, 0, sizeof(x));
        x[0]=0;
        do
        {
            x[++x[0]]++;
            n/=10;
        }
        while(n);
    }*/
    HN operator /(long long k)
    {
        long long r=0;
        for(int i=x[0];i>0;i--)
        {
            r=r*10+x[i];
            x[i]=r/k;
            r%=k;
        }
        while(x[0]>1 && !x[x[0]])
            --x[0];
        if(r!=0)
        {
            int carry=1;
            for(int i=1;carry==1 && i<=x[0];i++)
            {
                x[i]+=carry;
                carry=x[i]/10;
                x[i]%=10;
            }
            if(carry==1)x[++x[0]]=1;
        }
        return *this;
    }
    HN operator *(long long k)
    {
        long long r=0;
        for(int i=1;i<=x[0];i++)
        {
            long long temp=x[i]*k+r;
            x[i]=temp%10;
            r=temp/10;
        }
        while(r)
        {
            x[++x[0]]=r%10;
            r/=10;
        }
        return *this;
    }
    void scan(void)
    {
        char c;
        x[0]=0;
        scanf("%c", &c);
        while(c!='\n')
        {
            c-='0';
            x[++x[0]]=c;
            scanf("%c", &c);
        }
        for(int i=1;i<=x[0]/2;i++)
        {
            int aux=x[i];
            x[i]=x[x[0]-i+1];
            x[x[0]-i+1]=aux;
        }
    }
    void print()
    {
        for(int i=x[0];i>0;i--)
            printf("%d", x[i]);
        printf("\n");
    }
};

int main()
{
    freopen("next.in", "r", stdin);
    freopen("next.out", "w", stdout);
    HN n;
    long long d;
    n.scan();
    scanf("%lld", &d);
    n=n/d;
    n=n*d;
    n.print();
    return 0;
}