SWUST OJ58:添加反转数字

题目描述

马里迪内西亚的古董喜剧演员更喜欢喜剧而不是悲剧。不幸的是,大多数古代戏剧都是悲剧。因此,ACM的戏剧顾问决定将一些悲剧变成喜剧。显然,这项工作非常艰难,因为戏剧的基本感觉必须保持完整,尽管所有事物都变为对立面。例如数字:如果悲剧中出现任何数字,则必须将其转换为反向形式,然后才能被接受为喜剧。

反转数字是用阿拉伯数字书写的数字,但数字的顺序是反转的。第一个数字变为最后一个,反之亦然。例如,如果主角在悲剧中有1245个草莓,那么他现在有5421个草莓。请注意,省略了所有前导零。这意味着如果数字以零结尾,则零将通过反转丢失(例如,1200给出21)。另请注意,反转的数字永远不会有任何尾随的零。

ACM 需要使用反向数字进行计算。您的任务是将两个反转的数字相加并输出其反转的总和。当然,结果不是唯一的,因为任何特定数字都是几个数字的反向形式(例如,21在反转之前可以是12,120或1200)。因此,我们必须假设反转不会丢失零(例如,假设原始数字为12)。

输入

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.

输出

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.

样例输入

3
24 1
4358 754
305 794

样例输出

34
1998
1
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<malloc.h>
#define INF 0x3f3f3f3f
#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x>y?y:x)
#define M 100
int reverse(int a)
{
	int temp = 0;
	while (a!=0)
	{
		temp = temp * 10 + a % 10;
		a /= 10;
	}
	return temp;
}
int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int m, k;
		scanf("%d%d", &m, &k);
		int num1=reverse(m);
		int num2=reverse(k);
		int num3 = num1 + num2;
		int num4 = reverse(num3);
		printf("%d\n", num4);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值