Cod sursa(job #1905377)

Utilizator TESTHARD123TEST CENTRE TESTHARD123 Data 6 martie 2017 01:13:41
Problema A+B Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 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;
}
long long f,g;
int B[10000000];
int A[10000000];
long long 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++;   
    

if ((g+f)==total) fout<<total;
//cout<<g+f;
return 0;
}