B-adding reversed numbers

Source: Internet
Author: User
B-adding reversed numbers Time limit:2000 ms Memory limit:65536kb 64bit Io format:% LLD & % llusubmit status

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. 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 participant number is a reversed form of 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 the reversed numbers you are to add.


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.


Sample Input



3
24 1
4358 754
305 794


Sample output



34
1998
1 ////// it's killing me. I thought it was a big number operation.
#include<iostream>using namespace std;int main() {     int f(int);     int i,n,a,b,t;     cin>>n;    while(n--)    {        cin>>a>>b;         t=f(f(a)+f(b));         cout<<t<<endl;     } } int f(int m) {     int r=0;     while(m)    {         r=r*10+m%10;         m=m/10;          }     return r; } 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.