fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. string a, b, c, t;
  7. cin >> a >> b;
  8. int n=b.size(), nho=0, them;
  9. if (a.size()>b.size()) // Khúc này là em cho chiều dài 2 xâu = nhau
  10. {
  11. them=a.size()-b.size();
  12. for (int i=1; i<=them; i++) t+='0';
  13. b=b.insert(0, t);
  14. }
  15. if (b.size()>a.size())
  16. {
  17. them=b.size()-a.size();
  18. for (int i=1; i<=them; i++) t+='0';
  19. a=a.insert(0, t);
  20. }
  21. for (int i=a.size()-1; i>=0; i--)
  22. {
  23. int so, kt=0;
  24. so=(a[i]-48)+(b[i]-48)+nho;
  25. if (so>=10)
  26. {
  27. nho=1;
  28. so=so-10; //Cái này là biến nhớ để cộng cho số sau
  29. kt=1;
  30. }
  31. if (so<10&&kt!=1)
  32. nho=0;
  33. c+=(so+48);
  34. }
  35. for (int i=c.size(); i>=0; i--) cout << c[i] ;
  36. }
Success #stdin #stdout 0s 3460KB
stdin
111 222
stdout
333