-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathADDREV.cpp
More file actions
42 lines (36 loc) · 867 Bytes
/
Copy pathADDREV.cpp
File metadata and controls
42 lines (36 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <math.h>
using namespace std;
int digits(long int x) //funtion to return the number of digits of a long int
{
return (int)(log10(x)+1);
}
long rev(long x) //funtion to return the reversed number using the digits funtion
{
long revd=0;
int n=digits(x);
for(int i=1;i<=n;i++) //looping for the number of digits
{
revd+=(x%10)*pow(10,n-i); //reversing the number
x/=10; //dividing the number by 10
}
return revd;
}
int main()
{
long n1, n2;
int t;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>n1>>n2;
while(n1%10==0) //getting rid of trailing zeroes
n1=n1/10;
while(n2%10==0) //getting rid of trailing zeroes
n2=n2/10;
long ans = rev(rev(n1)+rev(n2)); //putting it all together
while(ans%10==0) ans=ans/10; //removing traling zeroes from answer
cout<<ans<<endl;
}
return 0;
}