-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreverseadd.cpp
More file actions
79 lines (64 loc) · 959 Bytes
/
reverseadd.cpp
File metadata and controls
79 lines (64 loc) · 959 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <vector>
#include <math.h>
using namespace std;
long long int reverse(long long int a)
{
int c;
int count=0;
std::vector<long long int> v;
while(a > 9)
{
c=a%10;
v.push_back(c);
a=a/10;
count++;
}
v.push_back(a);
long long int sum=0;
long long int j=0;
for (int i = count; i > 0; --i)
{
v[j]*=pow(10,i);
sum+=v[j];
j++;
}
//cout<< sum+a << endl;
return sum+a;
}
int main()
{
int test;
cin >> test;
while(test--)
{
long long int a ,b ;
cin >> a >> b;
long long int rev_a;
long long int rev_b;
if( a > 9 )
{
rev_a=reverse(a);
}
else
{
rev_a=a;
}
if (b>9)
{
rev_b = reverse(b);
}
else
{
rev_b =b;
}
long long int final_sum= rev_b + rev_a;
//cout << final_sum << endl;
final_sum = reverse(final_sum);
cout << final_sum << endl;
}
return 0;
}