题目描述
马里迪内西亚的古董喜剧演员更喜欢喜剧而不是悲剧。不幸的是,大多数古代戏剧都是悲剧。因此,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; }
SWUST OJ58:添加反转数字
最新推荐文章于 2024-05-30 21:35:46 发布