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. 追女神助手v0.1

    #-*-coding:utf8-*- import smtplib from email.mime.text import MIMEText import requests from lxml imp ...

  2. 类相关的BIF

    1.>>> issubclass(C,A)#判断c是A的子类,返回真假 2.>>> isinstance(b1,B) #判断c1是B类的实例化对象,返回真假 3.& ...

  3. Spring Cloud学习笔记-006

    服务容错保护:Spring Cloud Hystrix 在微服务架构中,我们将系统拆分成了很多服务单元,各单元的应用间通过服务注册与订阅的方式互相依赖.由于每个单元都在不同的进程中运行,依赖通过远程调 ...

  4. IdentityServer4-介绍大纲(译文)

    简介 IdentityServer4是一个基于ASP.NET CORE2使用OAuth2.0协议和OpenID Connect的框架 特性如下: Authentiaction作为一个Service 集 ...

  5. Linux OpenGL 实践篇-2 创建一个窗口

    OpenGL 作为一个图形接口,并没有包含窗口的相关内容,但OpenGL使用必须依赖窗口,即必须在窗口中绘制.这就要求我们必须了解一种窗口系统,但不同的操作系统提供的创建窗口的API都不相同,如果我们 ...

  6. JavaScript, 函数是实现异步的基础

    昨天一朋友和我聊到JS中的异步和同步, 后来从异步和同步的问题中得出了函数的另一面, 觉得挺不错, 特此分享一下 ==== 追梦子: 聊天是同步还是异步 小A: 异步 小A: 和你聊还可以和别人聊 追 ...

  7. [ABP]浅谈工作单元 在整个 ABP 框架当中的应用

    ABP在其内部实现了工作单元模式,统一地进行事务与连接管理. 其核心就是通过 Castle 的 Dynamic Proxy 进行动态代理,在组件注册的时候进行拦截器注入,拦截到实现了 Unit Of ...

  8. pyquery 的用法 --爬虫解析库

    如果你对Web有所涉及,如果你比较喜欢用CSS选择器,如果你对jQuery有所了解,那么这里有一个更适合你的解析库--pyquery. 接下来,我们就来感受一下pyquery的强大之处. 1. 准备工 ...

  9. 17.10.31&11.01

    10.31模拟考试 Prob.1(AC)裸的矩阵幂 Prob.2(WA)(类似括号匹配求合法方案数) 卡特兰数的一个模型运用.可以推出一个式子(推导方法一个erge讲的,一个骚猪讲的) Prob.3( ...

  10. 数论:px+py 不能表示的最大数为pq-p-q的证明

    对于互质的两个数p,q,px+py 不能表示的最大数为pq-p-q. 证明: 先证:pq-p-q不能被px+py表示. 假设pq-p-q可以被px+py表示 那么 px+py=pq-p-q       ...