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: | 2010-08-07 |
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
|
|||||||
2011-11-18 08:34:21 RR
Hi, can you tell me what's wrong with my #6046151 ? I got accepted in ADDREV & I tried all the tests I could think of & the tests posted here but could not find my mistake :( Last edit: 2011-11-18 11:32:06 |
|||||||
2011-09-07 22:24:33 Piotr KÄ…kol
@hallvabo - And I thought that code in C would be much longer. :P Congratulations! :-) Up to 100. |
|||||||
2011-09-07 22:18:10 Hallvard Norheim Bø
This was a lot harder to do in C than expected. I'll leave the task of beating 224 bytes to other C golfers :) @Piotr: how many digits can the numbers have? Last edit: 2011-09-07 22:19:10 |
|||||||
2011-04-19 03:33:28 512_I
finally got AC but still thinking y it was WA when i was removing trailing 0s from string of integer :P |
|||||||
2011-04-18 23:34:45 Piotr KÄ…kol
@512_I - I've written here a test for which Your program gives WA. ;-) |
|||||||
2011-04-17 07:19:06 512_I
i hav submmited same solution as of classical problem but got WA dont know why? |
|||||||
2011-01-19 12:37:48 HWK
Thanks a lot. Though I matched Nabb with another solution in this task I think with this (perhaps) new approach the competition could start over. |
|||||||
2011-01-18 13:51:09 Piotr KÄ…kol
Now I get it, thanks for the explanation! :-) I think I'm able to write such judge so I'll try and inform You about the result. :-) If I succeed, I'll change all the judges in my tasks but You'll have to submit Your solutions again because it would slow SPOJ down a lot. So be patient. ;-) Last edit: 2011-01-18 13:51:28 |
|||||||
2011-01-17 17:48:11 HWK
It's not a feature of Bash. All (?)languages could make such an output (see my PM). It's a "problem" of the evaluation. I don't know how the judge is implemented but I think at the moment it gets the bytes written to stdout, standardizes the whitespaces and compares the result with the desired result. To recognize my answer as right the judge has to know the output on the screen. Therefore it must handle the "control codes" (after my PM I think You know what I mean) correctly. I don't know how difficult to implement it is. But I really enjoy the trick of my solution and think it could be interesting for other solutions too. Thus I've asked. Last edit: 2011-01-17 17:51:52 |
|||||||
2011-01-17 13:27:16 Piotr KÄ…kol
So perhaps You should ask on spoj.pl/forum to add this feature(?) to Bash? Because I am just able to add languages, not improve them. |