Cod sursa(job #2412400)

Utilizator iulianarsenoiuArsenoiu Iulian iulianarsenoiu Data 22 aprilie 2019 11:06:25
Problema Next Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <algorithm>

using namespace std;
ifstream f("next.in");
ofstream g("next.out");
int i,a[1000005],b[105],c[1000055];
long long d;
char ch;
int rest(int d)
{
    int t=0;
    for(int i=1; i<=a[0]; i++)
    {
        t=t*10+a[i];
        t=t%d;
    }
    return t;
}
void adun()
{
    int t=0;
    for(int i=1; i<=max(a[0],b[0]); i++)
    {
        c[++c[0]]=a[i]+b[i]+t;
        t=c[i]/10;
        c[i]%=10;
    }
    if(t!=0)
        c[++c[0]]=t;
}
int main()
{
    while(f.get(ch))
    {
        if(ch=='\n')
            break;
        a[++a[0]]=ch-'0';
    }
    f>>d;
    if(rest(d)!=0)
        d-=rest(d);
    else
        d=0;
    reverse(a+1,a+a[0]+1);
    while(d!=0)
    {
        b[++b[0]]=d%10;
        d/=10;
    }
    adun();
    reverse(c+1,c+c[0]+1);
    for(i=1; i<=c[0]; i++)
        g<<c[i];
    g<<'\n';
    return 0;
}