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. 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

 /*
author:WTZPT
Time:2017.7.17
Title:Adding Reversed Numbers
*/
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int length(int num){ //测试数据长度
int i = ;
while(num){
num /= ;
i++;
}
return i;
} int trans(int num ,int len){
int temp,sum;
sum = ;
while(num){
temp = num % ;
sum += temp*((int)pow(10.0,(len-)*1.0));
num /= ;
len--; }
return sum;
}
int main()
{
int n,num1,num2,len1,len2,sum1,sum2,sum,len3,num;
while(cin>>n){
for(int ii = ; ii < n; ii++)
{
sum = ;
scanf("%d %d",&num1,&num2);
len1 = length(num1); //数据长度
len2 = length(num2);
//cout<<len1<<" "<<len2<<endl; 测试获取长度函数
sum1 = trans(num1,len1);//获得转化后数
sum2 = trans(num2,len2);
//cout<<sum1<<" "<<sum2<<endl; 测试第一次转化
sum = sum1 + sum2;
len3 = length(sum);
num = trans(sum,len3);
cout<<num<<endl;
} }
return ;
}

参考:

  http://blog.csdn.net/shiow1991/article/details/7220318

ACM Adding Reversed Numbers(summer2017)的更多相关文章

  1. zoj 2001 Adding Reversed Numbers

    Adding Reversed Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB The Antique Comedians of M ...

  2. poj1504 Adding Reversed Numbers

    Adding Reversed Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17993 Accepted: 9 ...

  3. Humble Numbers(hdu1058)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. zoj2001 Adding Reversed Numbers

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2001 Adding Reversed Numbers Time ...

  5. 【CF55D】Beautiful numbers(动态规划)

    [CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...

  6. ACM博弈知识汇总(转)

    博弈知识汇总 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍或是围棋子等等均可.两个人轮流从堆中取物体若干,规定最后取光物体者取胜.这是我国民间很古老的一个游戏,别看这游戏极其简单,却蕴含着深刻 ...

  7. 一位ACM过来人的心得(转)

    励志下! 刻苦的训练我打算最后稍微提一下.主要说后者:什么是有效地训练? 我想说下我的理解.很多ACMer入门的时候,都被告知:要多做题,做个500多道就变牛了.其实,这既不是充分条件.也不会是必要条 ...

  8. Round Numbers(组合数学)

    Round Numbers Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tota ...

  9. PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)

    1023 Have Fun with Numbers(20 分) Notice that the number 123456789 is a 9-digit number consisting exa ...

随机推荐

  1. Java中对List去重, Stream去重

    问题 当下互联网技术成熟,越来越多的趋向去中心化.分布式.流计算,使得很多以前在数据库侧做的事情放到了Java端.今天有人问道,如果数据库字段没有索引,那么应该如何根据该字段去重?大家都一致认为用Ja ...

  2. requests-认证设置

    #如果需要用户名和密码才能登陆网站,则需要认证设置auth=() import requests response = requests.get(url,auth=('user','password' ...

  3. urlopen()&urlretrieve()

    1.urlopen()方法 urllib.request.urlopen(url[,data[,proxies]]) 创建一个表示远程url的类文件对象,然后像本地文件一样的操作这个类文件对象来获取远 ...

  4. JS字符串和数组常用方法

    1.indexOf() – 返回字符串中一个字符第一处出现的索引,接收2个参数:要查找的字符,从哪个位置开始查找:.lastIndexOf()--返回字符串中某一个字符最后一次出现的索引值. 如果没有 ...

  5. 有意思的c++题目

    #include <iostream> #include<stdlib.h> using namespace std; class A { public: int _a; A( ...

  6. [Linux]_ELVE_ssh登录远程阿里服务器

    0x00  背景 最近新开了一个服务器,每次都用网页操作太麻烦,索性就用软件登录(貌似界面还有vim支持的也比网页的好),在网上寻找半天,找到一个软件,感觉特别好, 名叫:mobaxterm,好像是免 ...

  7. OpenGL中glUniform1i使用

    在OpenGL中使用glGetUniformLocation和glUniformxxx等函数时,要在之前启用对应的着色器程序,即调用glUseProgram.

  8. MSIL实用指南-闭包的生成和调用

    闭包(Closure)是词法闭包(Lexical Closure)的简称.对闭包的具体定义有很多种说法,这些说法大体可以分为两类: 一种说法认为闭包是符合一定条件的函数,比如参考资源中这样定义闭包:闭 ...

  9. Java 线程池原理分析

    1.简介 线程池可以简单看做是一组线程的集合,通过使用线程池,我们可以方便的复用线程,避免了频繁创建和销毁线程所带来的开销.在应用上,线程池可应用在后端相关服务中.比如 Web 服务器,数据库服务器等 ...

  10. [Codeforces 505C]Mr. Kitayuta, the Treasure Hunter

    Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The is ...