In this post I will show you my approach to adding reversed numbers.
This problem occurred during the ACM Central European Programming Contest, in Prague in 1998.

General description of the problem


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.


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.


Sample input:

24 1
4358 754
305 794

Sample output:



Exemplary approach

  1. In the first line of the input, we put number of the lines to process.
  2. In the next lines, we put numbers split by space, in which we should reverse order of the digits and then add them.
  3. In the final step, we should reverse order of the digits in the generated data and write result to the output.

Proposal of the solution in the Ruby language

hint: if you cannot see the code below, please disable AdBlock on this site (I don’t have advertisements, but I’m using Gist)