2019牛客暑期多校训练营(第七场)J A+B problem

mac2022-06-30  38

链接:https://ac.nowcoder.com/acm/contest/887/J来源:牛客网

题目描述

Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. And all the leading zeros are omitted. For example: the reversed number of 1234 is 4321. The reversed number of 1000 is 1. We define reversed number of as . Given you two positive integers and , you need to calculate the reversed sum: .

输入描述:

The first line of the input gives the number of test cases, T (T≤300)T\ (T \leq 300)T (T300). test cases follow.For each test case, the only line contains two positive integers: and . (1≤A,B≤231−11 \leq A, B \leq 2^{31}-11A,B2311)

输出描述:

For each test case, output a single line indicates the reversed sum. 示例1

输入

复制 3 12 1 101 9 991 1

输出

复制22 11 2 思路:  本来想用高精度来求,反噬却总是wa,只能看大佬代码 #include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long #define eps 1e-9 const int inf = 0x3f3f3f3f; const int mod = 1e9+7; ll f(ll a) { ll t = 0; while(a) { t = t * 10 + a % 10; a /= 10; } return t; } ll a, b; int main() { int t; for(scanf("%d", &t); t--; ) { scanf("%lld%lld", &a, &b); printf("%lld\n", f(f(a) + f(b))); } return 0; }

 

转载于:https://www.cnblogs.com/RootVount/p/11344588.html

最新回复(0)