#include <iostream> #include <bitset> #include <vector> #include <algorithm> #include <cmath> using namespace std; const string TEMP = "01234565789"; void reverseString(string &a) { for (int i = 0; i < a.size()/2; i++) swap(a[i],a[a.size()-i-1]); } void solve() { int tmp=0; string a, b, ans; cin >> a >> b; if (a.size() < b.size()) swap(a,b); reverseString(a); reverseString(b); for (int i = 0; i < b.size(); i++) { tmp += (a[i]-'0'); tmp += (b[i]-'0'); ans += TEMP[tmp%10]; tmp /= 10; } for (int i = b.size(); i < a.size(); i++) { tmp += (a[i]-'0'); ans += TEMP[tmp%10]; tmp /= 10; } if (tmp > 0) ans += "0"; reverseString(ans); cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); cout << '\n'; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include <iostream> #include <bitset> #include <vector> #include <algorithm> #include <cmath> using namespace std; const string TEMP = "01234565789"; void reverseString(string &a) { for (int i = 0; i < a.size()/2; i++) swap(a[i],a[a.size()-i-1]); } void solve() { int tmp=0; string a, b, ans; cin >> a >> b; if (a.size() < b.size()) swap(a,b); reverseString(a); reverseString(b); for (int i = 0; i < b.size(); i++) { tmp += (a[i]-'0'); tmp += (b[i]-'0'); ans += TEMP[tmp%10]; tmp /= 10; } for (int i = b.size(); i < a.size(); i++) { tmp += (a[i]-'0'); ans += TEMP[tmp%10]; tmp /= 10; } if (tmp > 0) ans += "0"; reverseString(ans); cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); cout << '\n'; return 0; } |