Pagini recente » Cod sursa (job #2375677) | Cod sursa (job #2889687) | Cod sursa (job #572823) | Cod sursa (job #1057080) | Cod sursa (job #1905370)
#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;
}