forked from love1024/spoj-solution-with-explanation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADDREV.cpp
55 lines (41 loc) · 1.16 KB
/
ADDREV.cpp
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
#include<bits/stdc++.h>
using namespace std;
//creating alias for long long
//in case if number is large
typedef long long ll;
//function to reverse a given num
ll reverseNumber(ll num) {
//declaring new variable to store result
ll newNum = 0;
//we take last digit of given num add it
//to the result and divide the given num
//by 10 so we check if remaining num is
//greater than 0
while(num > 0) {
//Adding last digit of given number to result
newNum = newNum*10 + (num%10);
//dividing number by 10 to get rid of last digit
num /= 10;
}
//returning reversed number
return newNum;
}
int main() {
//variable to store number of test cases
ll t;
cin>>t;
//looping over all test cases
while(t--) {
//declaring some variables to store temp values
ll a,b,c;
//taking in input two given numbers
cin>>a>>b;
//reversing the given two numbers and adding them
a = reverseNumber(a);
b = reverseNumber(b);
c = a+b;
//reversing the added number and printing it.
c = reverseNumber(c);
cout<<c<<endl;
}
}