Source: Internet
Author: User

Adding Reversed Numbers Time limit: 2 Seconds Memory Limit: 65536 KB

The antique comedians of Malidinesia prefer comedies to tragedies. Unfortunately, the most of the ancient plays is tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously very hard because the basic sense of the play must be kept intact, although all the things to their opposites. For example the Numbers:if no number appears in the tragedy, it must is converted to its reversed form before being ACCE Pted into the comedy play.

Reversed number is a number written in Arabic numerals and 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 had 5421 of them now. Note that all the leading zeros is omitted. That means if the number ends with a zero, the zero was lost by reversing (e.g. gives 21). Also Note that the reversed number never have any trailing zeros.

ACM needs to calculate with reversed numbers. Your task is to add the reversed numbers and output their reversed sum. Of course, the result is no unique because any particular number are a reversed form of several numbers (e.g. could be Before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume, 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 of the consists of exactly one line with the positive integers separated by space. These is the reversed numbers you is to add.

Output

For each case, print exactly one line containing only one integer-the reversed sum of the reversed numbers. Omit any leading zeros in the output.

Sample Input

3
24 1
4358 754
305 794

Sample Output

34
1998
1

The main topic: it is easy to understand, is to give the title of the two number of reverse, and then output in flashbacks ~

See the code.

`1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intMain ()8 {9     intN;Tenscanf"%d",&n); One      while(n--) A     { -         Chara[ -],b[ -]; -scanf"%s%s", A, b); the         intlen1=strlen (a); -         intLen2=strlen (b); -         intsum1=0; -          for(intI=len1-1; i>=0; i--) +Sum1=sum1*Ten+a[i]-'0'; -         intSum2=0; +          for(inti=len2-1; i>=0; i--) Asum2=sum2*Ten+b[i]-'0'; at         intsum=sum1+sum2; -         ints=0; -          while(sum) -         { -s=sum%Ten+s*Ten; -Sum/=Ten; in         } -printf ("%d\n", s); to     } +     return 0; -}`

The second is relatively simple.

`1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 intFunintk)7 {8     intsum=0;9      while(k)Ten     { Onesum=k%Ten+sum*Ten; AK/=Ten; -     } -     returnsum; the } -  - intMain () - { +     intn,a,b; -scanf"%d",&n); +      while(n--) A     { atscanf"%d%d",&a,&b); -printf ("%d\n", Fun (a) +Fun (b))); -     } -     return 0; -}`

Related Keywords:

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.