Cod sursa(job #2180836)

Utilizator filiptudose2007Tudose Filip filiptudose2007 Data 21 martie 2018 11:16:39
Problema Next Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("next.in");
ofstream g("next.out");
int a[1000005],c[1000005],b[1000005],j;
long long i,d,t,rest;
char x;
int main()
{
    f.get(x);
    while(x!='\n')
    {
        a[++a[0]]=x-'0';
        f.get(x);
    }
    reverse(a+1,a+a[0]+1);
    f>>d;
    i=a[0];
    while(i)
    {
        rest=rest*10+a[i];
        rest=rest%d;
        i--;
    }
    t=d-rest;
    i=1;
    if (rest==0) for (i=a[0]; i>=1; i--) g<<a[i];
    else
    {
        c[0]=0;
        while (t>0)
            c[++c[0]]=t%10,t/=10;
        i=1;
        t=0;
        while(i<=a[0] || i<=c[0] || t>0)
        {
            t=t+a[i]+c[i];
            b[i]=t%10;
            t/=10;
            i++;
        }
        for(j=i-1; j>=1; --j)
            g<<b[j];

    }

    return 0;
}