-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathADDREV - Adding Reversed Numbers
54 lines (51 loc) · 1.2 KB
/
ADDREV - Adding Reversed Numbers
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
#include<iostream>
#include<math.h>
using namespace std;
long quick_pow10(int n)
{
static long pow10[12] = {
1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000
};
return pow10[n];
}
long reverseint(long firstnum){
long temp = 10;
int count = 0;
while(firstnum%temp!=firstnum){
temp = temp*10;
count = count + 1;
}
count =count+1;
temp=0;
int count1=1;
while(count){
if (count1==1){
temp = firstnum%quick_pow10(count1)*quick_pow10(count-1);
}
else
{
temp = temp + (((firstnum%quick_pow10(count1))-(firstnum%quick_pow10(count1-1)))/quick_pow10(count1-1))*quick_pow10(count-1);
}
count--;
count1++;
}
return temp;
}
int main(void)
{
int testcases;
cin>>testcases;
while(testcases){
unsigned long firstnum;
unsigned long secondnum;
unsigned long sum;
unsigned long reversedsum;
cin>>firstnum;
cin>>secondnum;
sum = reverseint(firstnum) + reverseint(secondnum);
cout<<reverseint(sum)<<endl;
testcases--;
}
return 0;
}