#include <bits/stdc++.h>
using namespace std;
int dod[5010];
string a, b;
int wyn[5010];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>a>>b;
if(b.size() > a.size()) swap(a,b);
int dodzer = a.size()-b.size();
string zera;
for(int i=0; i<dodzer; i++)
zera+='0';
a = '0'+a;
b = '0'+zera+b;
for(int i=a.size()-1; i>=0; i--){
int A = (int)a[i] - 48;
int B = (int)b[i] - 48;
int AB = A+B+dod[i];
int reszta = AB%10;
int przenies = ((AB>9)?1:0);
wyn[i] = reszta;
dod[i-1] = przenies;
}
bool x = true;
if(wyn[0] != 0) x=false;
for(int i=0;i<a.size(); i++){
if(wyn[i] == 0 && x == true){x = false; continue;}
cout<<wyn[i];
}
}
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 | #include <bits/stdc++.h> using namespace std; int dod[5010]; string a, b; int wyn[5010]; int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>a>>b; if(b.size() > a.size()) swap(a,b); int dodzer = a.size()-b.size(); string zera; for(int i=0; i<dodzer; i++) zera+='0'; a = '0'+a; b = '0'+zera+b; for(int i=a.size()-1; i>=0; i--){ int A = (int)a[i] - 48; int B = (int)b[i] - 48; int AB = A+B+dod[i]; int reszta = AB%10; int przenies = ((AB>9)?1:0); wyn[i] = reszta; dod[i-1] = przenies; } bool x = true; if(wyn[0] != 0) x=false; for(int i=0;i<a.size(); i++){ if(wyn[i] == 0 && x == true){x = false; continue;} cout<<wyn[i]; } } |
English