Cod sursa(job #885347)

Utilizator asdqwerChindris Mihail asdqwer Data 21 februarie 2013 21:20:57
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <string.h>
using namespace std;

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

char a[2000000001],b[2000000002];

int main()
{
    char *p,*q,*p2;
    short x;
    strrev(a);
    strrev(b);
    for(p=a,q=b;*p!=0 && *q!=0;q++,p++)
    {
        x=*p-'0'+*q-'0'>9;
        if(x>9)
        {
            p2=p;
            while(*p2=='9')
                p2++;
            if(*p2=0)
                *p2='1';
            else
                *p2++;
            x%=10;
            *q=x+'0';
        }
        else
            *q=x+'0';
    }
    strrev(b);
    g<<b;
    f.close();
    g.close();
    return 0;
}