既然头和尾要相加,那么如果使用int来存数字并做到翻转相加相对麻烦
那么类似高精度的计算一般,使用char数组来存每一个位置的数字,来简化。
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl "\n"
void slu() {
string a;
cin >> a;
int res = 0;
for (int i = 0; i < a.size(); i++) {
res *= 10;
res += (a[i] - '0') + (a[a.size() - i - 1] - '0');
}
cout << res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
// cin >> T;
T = 1;
while (T--)slu();
}

京公网安备 11010502036488号