# RPH001- Editorial

Setter: rohan101
Tester: rohan101
Editorialist:rohan101

DIFFICULTY:
Easy-Medium

PREREQUISITES:
Array, Basic Maths

Explanation:
Both the numbers were supposed to reversed and added and reversed again while printing.
The leading zeroes were to be removed as mentioned in the output.

Time Complexity:
O(length of number)

Setter Solution:
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
String a = sc.next();
String s = sc.next();
StringBuilder ss = new StringBuilder(a);
ss = ss.reverse();
StringBuilder ss2 = new StringBuilder(s);
ss2 = ss2.reverse();
BigInteger b = new BigInteger(ss.toString());
BigInteger c = new BigInteger(ss2.toString());
StringBuilder ans=new StringBuilder(c.toString());
ans=ans.reverse();
while(ans.charAt(0)==‘0’)
{
ans=ans.deleteCharAt(0);
}
System.out.println(ans);
}

Alternate solution:
for _ in range(int(input())):
a, b = map(str, input().split())
a = a[::-1]
b = b[::-1]
c = int(a) + int(b)
x = str(c)
print(int(x[::-1]))

Could someone please explain the Output a little bit? From what I’ve understood, this should be the code but it’s not working.

``````#include <iostream>
#include <cmath>
using namespace std;

int revNum(int n){
int rem,rev=0,temp = n, nod=0;
while(temp){
temp = temp/10;
nod++;
}
for(int i=0;i<nod;i++){
rem = n%10;
rev += rem*(pow(10,(nod-i-1)));
n = n/10;
}
return rev;
}

int main() {

int t,a,b;
cin>>t;
while(t--){
cin>>a>>b;

cout<<revNum(revNum(a)+revNum(b))<<endl;
}

return 0;
}``````