Cod sursa(job #1628692)

Utilizator pibogaBogdan piboga Data 4 martie 2016 10:07:57
Problema A+B Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <cstring>

using namespace std;

ifstream fin ("adunare.in");
ofstream fout ("adunare.out");

char c[1010],d[1010];
short int i,a[1010],b[1010],k,lg,j,t;

int main()
{
    fin >> c+1;
    fin >> d+1;

    a[0]=strlen(c+1);
    i=a[0];

    while (i>=1)
    {
        a[++k]=c[i]-'0';
        i--;
    }





    k=0; b[0]=strlen(d+1);
    i=b[0];

    while (i>=1)
    {
        b[++k]=d[i]-'0';
        i--;
    }



    lg=max(strlen(c+1),strlen(d+1));
    i=1;
    while (i<=lg+1)
    {
        a[i]=a[i]+b[i]+t;
        t=0;
        if (a[i]>9)
        {
            t=a[i]/10;
            a[i]%=10;
        }
        i++;
    }
    i--;
    if (a[i]==0) i--;
    for (j=i;j>=1;j--)
    {
        fout << a[j];
    }

    return 0;
}