-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddrev.cpp
51 lines (48 loc) · 908 Bytes
/
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
//DATE: 12/08/2015
//Author: Ramjeet Saran
//http://www.spoj.com/problems/ADDREV/
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
long int t;
cin>>t;
while(t--){
string A, B;
long long int lenA, lenB, out = 0;
cin>>A>>B;
lenA = A.length();
lenB = B.length();
long long int i = 0, j = 0;
long long int c = 0, mool;
while(i < lenA && j < lenB){
mool = c + (A[i] - '0') + (B[i] - '0');
out = out * 10 + mool % 10;
c = mool > 9 ? 1 : 0 ;
i++;
j++;
//cout<<out<<" "<<i+1<<endl;
}
while(i < lenA)
{
mool = c + (A[i] - '0');
out = out * 10 + mool % 10;
c = mool > 9 ? 1 : 0 ;
i++;
}
while(j < lenB)
{
mool = c + (B[j] - '0');
out = out * 10 + mool % 10;
c = mool > 9 ? 1 : 0 ;
j++;
}
if(c == 1)
out = out * 10 + c ;
cout<<out<<endl;
}
}