链接: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: .
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 (T≤300). 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}-11≤A,B≤231−1)
输出描述:
For each test case, output a single line indicates the reversed sum.
示例1
输出
复制2211 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 ", f(f(a) + f(b))); } return 0; }