/* Jakub Żojdzik 06-12-2022 */ #include <bits/stdc++.h> #ifdef LOCAL #include "debug.hpp" #else #define debug(...) #define dt #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<pair<int, int>> vpii; typedef vector<pair<long long, long long>> vpll; #define fi first #define se second #define pb push_back #define rep(i, x, y) for(ll i = (ll)x; i <= (ll)y; i++) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define nl cout << '\n' int main() { cout.tie(0); cin.tie(0)->sync_with_stdio(0); string a, b, c; cin >> a >> b; if(sz(a) < sz(b)) swap(a, b); for(int i = sz(b); i < sz(a); i++) { b = "0" + b; } a = "0" + a; b = "0" + b; int dalej = 0; for(int i = sz(a)-1; i >= 0; i--) { int temp = a[i] - '0' + b[i] - '0'; temp += dalej; dalej = 0; c += (temp%10) + '0'; temp /= 10; dalej += temp; } reverse(all(c)); if(c[0] == '0' && sz(c) != 1) cout << c.substr(1, sz(c)-1) << '\n'; else cout << c << '\n'; } /* */
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 55 56 57 58 59 60 61 62 63 64 65 66 | /* Jakub Żojdzik 06-12-2022 */ #include <bits/stdc++.h> #ifdef LOCAL #include "debug.hpp" #else #define debug(...) #define dt #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<pair<int, int>> vpii; typedef vector<pair<long long, long long>> vpll; #define fi first #define se second #define pb push_back #define rep(i, x, y) for(ll i = (ll)x; i <= (ll)y; i++) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define nl cout << '\n' int main() { cout.tie(0); cin.tie(0)->sync_with_stdio(0); string a, b, c; cin >> a >> b; if(sz(a) < sz(b)) swap(a, b); for(int i = sz(b); i < sz(a); i++) { b = "0" + b; } a = "0" + a; b = "0" + b; int dalej = 0; for(int i = sz(a)-1; i >= 0; i--) { int temp = a[i] - '0' + b[i] - '0'; temp += dalej; dalej = 0; c += (temp%10) + '0'; temp /= 10; dalej += temp; } reverse(all(c)); if(c[0] == '0' && sz(c) != 1) cout << c.substr(1, sz(c)-1) << '\n'; else cout << c << '\n'; } /* */ |