1504 Adding Reversed Numbers
来源:互联网 发布:网桥mac表 编辑:程序博客网 时间:2024/05/16 02:08
Description
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).
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
324 14358 754305 794
Sample Output
3419981
CODE:
#include <stdio.h>char buf[50];int atoi1(char* p){int n=0;for(;*p!='e';++p)n=n*10+*p;return n;}int rev(int a){int i;if(a==0) return 0;for(i=0;a>0;++i,a/=10)buf[i]=a%10;buf[i]='e';return atoi1(buf);}int main(int argc, char *argv[]) { int num,n1,n2,n3;scanf("%d",&num);while(num>0){scanf("%d%d",&n1,&n2);n1=rev(n1);n2=rev(n2);n3=n1+n2;n3=rev(n3);printf("%d\n",n3);--num;}return 0;}
- 1504 Adding Reversed Numbers
- pku 1504 Adding Reversed Numbers
- PKU 1504 Adding Reversed Numbers
- poj 1504 Adding Reversed Numbers
- poj 1504 Adding Reversed Numbers
- POJ 1504 adding reversed numbers
- POJ 1504 Adding Reversed Numbers
- POJ 1504 Adding Reversed Numbers
- POJ 1504 Adding Reversed Numbers
- POJ 1504:Adding Reversed Numbers
- poj 1504 Adding Reversed Numbers【反转数字】
- POJ 1504 Adding Reversed Numbers(水~)
- poj1504 Adding Reversed Numbers
- Adding Reversed Numbers
- Adding Reversed Numbers
- Adding Reversed Numbers
- B - Adding Reversed Numbers
- Adding Reversed Numbers
- 七夕恋歌
- 二叉树两结点最低公共祖先结点(二)
- 找出数组中唯一重复的数
- Mutex的lock(), tryLock()区别
- android中进行https连接的方式(源码)
- 1504 Adding Reversed Numbers
- Java虚拟机学习随笔(一)
- 教你使用把div层变成可编辑的状态,非常简单粗暴有效
- 使用NOSQL的MongoDB建立索引时需要注意的几点建议和Explain优化分析
- struts2的详细的复习讲解
- Android学习札记51:在TextView显示插入的图片
- linux cp 不提示overwrite
- 混合高斯模型Gaussian Mixture Model(GMM)的EM(Expectation Maxium)求解代码
- iOS GHUnit输出Junitxml格式log(为后续的hudson的整合做基础)