#include <iostream> using namespace std; string a,b; int as,bs,p; int main() { cin>>a>>b; if(b.size()>a.size())swap(a,b); else if(b.size()==a.size()&&b>a)swap(a,b); as=a.size(); bs=b.size(); for(int i=1;i<=as;i++) { if(bs>=i)a[as-i]+=b[bs-i]-'0'; a[as-i]+=p; p=0; if((int)(a[as-i]-'0')>9) { a[as-i]-=10; p=1; } } if(p)cout<<p; cout<<a; 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 | #include <iostream> using namespace std; string a,b; int as,bs,p; int main() { cin>>a>>b; if(b.size()>a.size())swap(a,b); else if(b.size()==a.size()&&b>a)swap(a,b); as=a.size(); bs=b.size(); for(int i=1;i<=as;i++) { if(bs>=i)a[as-i]+=b[bs-i]-'0'; a[as-i]+=p; p=0; if((int)(a[as-i]-'0')>9) { a[as-i]-=10; p=1; } } if(p)cout<<p; cout<<a; return 0; } |