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. Linux安装git和maven的详细过程

    一.使用yum安装git 当前安装环境是centos6.5 由于在CentOS6的yum源中已经有git的版本了,可以直接使用yum源进行安装 yum -y install git 由于centos6 ...

  2. 使用Vertx重构系统小结

    背景 前几个月,使用Vertx重构了公司的一个子系统,该系统负责公司核心数据subscriber的采集.处理.存储和搜索.这里介绍下重构该系统时的一些关键点. 架构 重构前系统部署图: 重构前系统主要 ...

  3. ACE之通信的设计空间

    本篇文章主要介绍 .无连接的和面向连接的协议之间的对比 .同步的和异步的消息交换之间的对比. .消息传递和共享内存之间的对比. 1:无连接和面向连接的协议对比 协议(protocol)是指一组规则,这 ...

  4. Cmder Windows 下的终端神器

    废话 Windows 下常用的终端有两个,古老的 cmd 和功能强大但你记不住函数的 PowerShell ,两者我都用过一段时间,给我的提体验是功能够用,界面丑陋,虽然 win10 下可以通过调整背 ...

  5. .NET CORE 2.0之 依赖注入在类中获取IHostingEnvironment,HttpContext

    在.NET CORE 中,依赖注入非常常见, 在原先的 HttpContext中常用的server.Mappath已经么有了如下: HttpContext.Current.Server.MapPath ...

  6. 视觉slam学习之路(一)看高翔十四讲所遇到的问题

      目前实验室做机器人,主要分三个方向,定位导航,建图,图像识别,之前做的也是做了下Qt上位机,后面又弄红外识别,因为这学期上课也没怎么花时间在项目,然后导师让我们确定一个方向来,便于以后发论文什么. ...

  7. [Ubuntu 16.04 LTS ]屏幕分辨率 Unknown display

    新装完Ubuntu 16.04 LTS 通过System settings-->Displays 设置屏幕分辨率 显示"Unknown display",选择后无反应,并且屏 ...

  8. 【悬赏征文】确认过眼神,你就是腾讯WeTest的特约撰稿人

    成功的经验从来不是一蹴而就的,它仰仗基于价值认同的信息互通,知识共享. 在开发.测试领域"摸爬滚打"多年的你,一定有很多经验与见解分享. 如何让更多同行了解自己的独到见解? 怎样才 ...

  9. [HNOI2012]排队

    题目描述 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不同的) 输入输 ...

  10. 51nod 1514 美妙的序列

    Description 长度为n的排列,且满足从中间任意位置划分为两个非空数列后,左边的最大值>右边的最小值.问这样的排列有多少个%998244353 题面 Solution 正难则反 \(f[ ...