ADDREV - Adding Reversed Numbers


The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.

Reversed number is a number written in Arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros.

ACM needs to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).

Input

The input consists of N cases (equal to about 10000). The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.

Output

For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output.

Example

Sample input: 
3
24 1
4358 754
305 794

Sample output:
34
1998
1

hide comments
sma5nico: 2020-12-22 09:52:38

ios_base::sync_with_stdio(false) can cause things to go wrong in ideone. Took me 5 attempts to realize.

bradp1tt: 2020-12-04 06:46:42

the year is 2050... java still doesnt have a builtin reverse method for int to int

harsha_96: 2020-09-09 15:45:11

I do these easy probs on spoj, whenever I cannot solve hard ones. a small dose of motivation :)

kishor_e: 2020-07-26 20:24:55

First problem for me to get AC in one go :|

surajxd: 2020-07-10 20:06:18

ac in one go... too easy.

dj_khalid: 2020-06-28 08:38:59

My first spoj problem ,AC in first go

sajin_amin02: 2020-06-23 20:56:38

AC in one go, xD

joshzegers: 2020-06-02 08:03:02

people who say "AC in one go" are just annoying

cre_jug_07: 2020-06-02 07:20:02

i had to convert the input to string then reverse it.Add them as int convert to str and reverse. IMP!!!!(( print them as "int" data types!!!

Last edit: 2020-06-02 07:21:25
landi58: 2020-04-30 16:21:33

AC in first Go, Don't use string or any shit. Just use int data type and cin and cout..thats it.
just a=reverse(a), b=reverse(b)
cout<<reverse(a+b)
Good luck..

Last edit: 2020-04-30 16:22:31

Added by:adrian
Date:2004-06-06
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:ACM Central European Programming Contest, Prague 1998