Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

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).


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.


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.


24 1
4358 754
305 794


Added by:Piotr Kąkol
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
2014-05-12 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: 2014-10-29 19:52:58
2014-05-11 21:05:00 Dominique VAILLANT
@Mitch: Beautiful!
2014-05-09 18:38:39 Mitch Schwartz
Maybe just leave the test data alone, and add a note about the issue to the problem statement?
2013-12-18 17:13:25 Piotr KÄ…kol
perl: command not found
2013-12-18 13:04:13 Linghui Liu
@Piotr, what's the matter with my 10688941? thank you in advance.
2013-11-22 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: 2013-11-22 17:02:18
2013-08-27 14:26:31 Dominique VAILLANT
@Piotr Kąkol: Thanks for response, it's now ok.
2013-08-19 17:12:13 Piotr KÄ…kol
It must have been some bug. When I submitted *919 now it got AC. Perhaps some SPOJ-related issue.
2013-08-14 11:56:58 Dominique VAILLANT
My submission #9834919 was AC, but after two strange WA with somewhat different code
I re-submit #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.
2011-11-28 14:37:25 Piotr KÄ…kol
@RR - For some tests You print blank line. For exmple for:
84724062990813110340391969338056640046267569872829960276132159914910758704804296104 220552902838040919625449936050294351743146942264128892888683833380476890687903337326526587960
© All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.