Cod sursa(job #1905370)

Utilizator TESTHARD123TEST CENTRE TESTHARD123 Data 6 martie 2017 01:07:16
Problema A+B Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("adunare.in");
ofstream fout("adunare.out");
inline void add(int A[], int B[]){
int i, t = 0;
for (i=1; i<=A[0] || i<=B[0] || t; i++, t/=10)
													A[i] = (t += A[i] + B[i]) % 10;
A[0] = i - 1;
}

int f,g;
int B[100000];
int A[100000];
int i,j,a,b;
int main(){
fin>>a>>b;
f=a;g=b;
while (a){ 

    A[++i] = a % 10;
    a /= 10; 
    A[0]=i;
} 
while (b) { 
    B[++j] = b % 10; 
    b /= 10; 
    B[0]=j;
}

add(A,B);

int nr=A[0];

int total=0;
    int exp=0;
    for(int i=1 ;i<=nr; i++)
    {
      if(A[i]>=10)
      {  
            int temp=A[i];
            while(temp)
            {
                 total+=(temp%10) * static_cast<int>(pow(10.0,exp));
                 temp/=10;
                 exp++;
            }
      }
      else
      {    
            total+=A[i]*static_cast<int>(pow(10.0,exp));
            exp++;
      }
    }

fout<<total;
cout<<g+f;
return 0;
}