Cod sursa(job #1134071)

Utilizator robertstrecheStreche Robert robertstreche Data 5 martie 2014 22:48:40
Problema Next Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <string.h>

using namespace std;

ifstream f("next.in");
ofstream g("next.out");

long long m,add,i,nr,r,rr,nrr;
char c,s[1000001];

int main()
{

   while (f>>noskipws>>c && c!='\n')
    s[++nrr]=c;

    f>>m;

    for (i=1;i<=nrr;i++)
      add=(add*10+s[i]-48)%m;

    add=(m-add)%m;

    //g<<add<<'\n';

     nr=nrr;

   while (add)
    {

        if (add%10+s[nr]-48+r>=10)
          rr=1;
        else
          rr=0;

        s[nr]=(add%10+s[nr]+r-48)%10+48;
        r=rr;
        add/=10;
        nr--;

    }

   if (rr)
    if (s[1]<'9')
     s[1]++;
    else
     {
         g<<1;
         s[1]=0;
     }
      for (i=1;i<=nrr;i++)
       g<<s[i];

   f.close();
   g.close();
}