Adding reversed numbers
Time limit:1000 ms |
|
Memory limit:10000 K |
Total submissions:12526 |
|
Accepted:6914 |
Description
The antique comedians of malidinesia prefer comedies to tragedies. unfortunately, most of the specified ent plays are tragedies. therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. obviusly, 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.
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,
Result is not unique because any participant number is a reversed form
Several numbers (e.g. 21 cocould 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. 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
Reversed numbers you are to add.
Output
For
Each case, print exactly one line containing only one integer-
Reversed sum of two reversed numbers. omit any leading zeros in
Output.
Sample Input
324 14358 754305 794
Sample output
3419981
Analysis:
(1) At first, I thought this integer may be a very large number, and the length of the integer or long integer is not enough. Therefore, we plan to simulate character arrays. The level is too low and errors keep occurring during the simulation. In a rage, I tried it with long. I could only say that the test data in the Ming project was not rigorous enough, so I got a hole in it.
(2) question meaning analysis: it refers to turning over the connected integers, adding them, and then turning over the output.
Source
# Include <stdio. h> Long Long Get_reverse ( Long Long Num ){ Long Long Result = 0 ; While (Num> 0 ) {Result = Result * 10 + Num % 10 ; Num = Num/ 10 ;} Return Result ;} Int Main (){ Long Long Num1, num2; Int N; scanf ( " % D " ,& N ); While (N -- ) {Scanf ( " % LLD " , & Num1 ,& Num2); num1 = Get_reverse (num1); num2 = Get_reverse (num2); num1 + = Num2; num1 =Get_reverse (num1); printf ( " % LLD \ n " , Num1 );} Return 0 ;}