Cod sursa(job #976478)

Utilizator Teddy.Kelly14Keller Victor-Theodor Teddy.Kelly14 Data 23 iulie 2013 12:33:34
Problema A+B Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>
using namespace std;
int a,b,i,A[100],B[100],x,k;
int main(){
    ifstream fin("adunare.in");
    ofstream fout("adunare.out");
    fin>>a>>b;
    x=a;
    k=0;
    while(x!=0){
        k++;
        A[k] = x%10;
        x=x/10;
    }
     A[0]=k;


    int m,S[100],t;
    x=b;
    k=0;
    while(x!=0){
        k++;
        B[k] = x%10;
        x=x/10;
    }
     B[0]=k;

    if(A[0]>B[0])
        m=A[0];
    else
        m=B[0];
    t = 0;
    for(i=1;i<=m;i++){
        x=A[i]+B[i]+t;
        S[i]=x%10;
        t = x/10;
    }
    S[0] = m;
    if (t!=0) {
        S[0]++;
        S[ S[0] ] = t;
    }

    for(i=S[0];i>=1;i--)
        fout<<S[i];

    return 0;
}