Submit  All submissions  Best solutions  Back to list 
ADDING  Adding reversed numbers (challenge) 
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 100). 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.
Warning: Even unsigned long long int isn't enought for this task.
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
Input:
3
24 1
4358 754
305 794
Output:
34
1998
1
Added by:  Piotr Kąkol 
Date:  20100807 
Time limit:  4.849s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS OBJC SCM qobi VB.NET 
Resource:  Copy of Adrian Kosowski's task ADDREV. 
hide comments


20140512 14:12:49 Mitch Schwartz
@Dominique: Thanks :) It could be nice for BF, but I prefer not to solve it twice if the problem will change. (Although I understand about being too busy, it's ok, I can wait.) @Piotr: Thanks for the test data update and the rejudge. :D Last edit: 20141029 19:52:58 

20140511 21:05:00 Dominique VAILLANT
@Mitch: Beautiful! 

20140509 18:38:39 Mitch Schwartz
Maybe just leave the test data alone, and add a note about the issue to the problem statement? 

20131218 17:13:25 Piotr KÄ…kol
perl: command not found 

20131218 13:04:13 Linghui Liu
@Piotr, what's the matter with my 10688941? thank you in advance. 

20131122 11:44:30 Mitch Schwartz
@Piotr: As primo mentioned on IRC a little while ago, the test case you gave to RR is invalid as one of the integers has a trailing zero, contradicting "Also note that the reversed number never has any trailing zeros". More info: I've confirmed that ADDREV follows this constraint; the same code gets AC there but NZEC here (see submission 10520262). Last edit: 20131122 17:02:18 

20130827 14:26:31 Dominique VAILLANT
@Piotr Kąkol: Thanks for response, it's now ok. 

20130819 17:12:13 Piotr KÄ…kol
It must have been some bug. When I submitted *919 now it got AC. Perhaps some SPOJrelated issue. 

20130814 11:56:58 Dominique VAILLANT
My submission #9834919 was AC, but after two strange WA with somewhat different code I resubmit #9834919 directly from SPOJ dialog box (no copy/paste, no keyboard entry), this submission is #9834983 but I got WA??? N.B. Idem for classical ADDREV. 

20111128 14:37:25 Piotr KÄ…kol
@RR  For some tests You print blank line. For exmple for: 84724062990813110340391969338056640046267569872829960276132159914910758704804296104 220552902838040919625449936050294351743146942264128892888683833380476890687903337326526587960 