B - Adding Reversed Numbers

B - Adding Reversed Numbers

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld
& %llu

Submit Status

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

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

///////坑死我了,我以为是大数运算呢。

#include<iostream>
using namespace std;
int main()
{
    int f(int);
    int i,n,a,b,t;
    cin>>n;
   while(n--)
    {
       cin>>a>>b;
        t=f(f(a)+f(b));
        cout<<t<<endl;
    }
}
int f(int m)
{
    int r=0;
    while(m)
    {
        r=r*10+m%10;
        m=m/10; 

    }
    return r;
} 

B - Adding Reversed Numbers

时间: 2024-10-09 22:35:49

B - Adding Reversed Numbers的相关文章

zoj 2001 Adding Reversed Numbers

Adding Reversed Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB 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

SPOJ Python Day1: Adding Reversed Numbers

水题就要水的滴水不漏=-=,第一个疗程博主决定按照SPOJ提交人数的顺序开始刷,主要任务在于熟悉Python. 42. Adding Reversed Numbers 题目非常简单 Sample input: 3 24 1 4358 754 305 794 第一行是下面输入的行数,主要说的事儿是把第一个数反过来,第二个数反过来,然后加一起,然后再把他们的和反过来.比如说24 1 这行吧: Step 1:24 –> 42, 1 –> 1 Step 2:42+1 = 43 Step 3:43 –&

UVA713 UVALive5539 POJ1504 ZOJ2001 Adding Reversed Numbers

Regionals 1998 >> Europe - Central 问题链接:UVA713 UVALive5539 POJ1504 ZOJ2001 Adding Reversed Numbers.入门练习题,用C语言编写. 题意简述:输入两个整数,都反转(逆序)后再求和,输出相加后反转(逆序)的结果. 问题分析:整数可能很大,大到200位:相加结果反转后左边的0需要去掉. 程序中封装了两个函数来实现,逻辑更加简单清晰. AC的C语言程序如下: /* UVA713 UVALive5539 PO

Adding Reversed Numbers(summer2017)

1 /* 2 author:WTZPT 3 Time:2017.7.17 4 Title:Adding Reversed Numbers 5 */ 6 #include<stdio.h> 7 #include<math.h> 8 #include<iostream> 9 using namespace std; 10 int length(int num){ //测试数据长度 11 int i = 0; 12 while(num){ 13 num /= 10; 14 i

zoj2001 Adding Reversed Numbers

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2001 Adding Reversed Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient pla

POJ 1504,ZOJ 2001,UVA 713, Adding Reversed Numbers,错误,已找到错误

------------------------------------------------------------ 以此题警告自己: 总结, 1.在数组的使用时,一定别忘了初始化 2.在两种情况复制代码时,一定要小心,注意修改变量名,一不留神就会带来不可估量的后果,一定要仔细挨着一个一个变量的修改,别跳着看着哪个变量就改哪一个变量! (这个题目中,就是复制了一下,代码,ca,我找了一下午的错....还好终于找到了,一个字母的错,) -----------------------------

POJ 1504 Adding Reversed Numbers

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16053   Accepted: 8786 Description The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor

SPOJ problem 42: Adding Reversed Numbers

这是一道水题,就是让你把给出的两个数倒置后相加再倒回来,模拟一下就行. #include<cstdio> int n,m,x,y,t; int main(){ for(scanf("%d",&t);t;t--){ scanf("%d%d",&n,&m); x=0;y=0; for (;n;n/=10)x=x*10+n%10; for (;m;m/=10)y=y*10+m%10; x+=y;y=0; for (;x;x/=10)y=

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY