fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdlib>
  4.  
  5. const int base = 1000*1000*1000;
  6.  
  7. using namespace std;
  8.  
  9. vector <int> convert (string s)
  10. {
  11. vector <int> vec1;
  12.  
  13. for (int i=(int)s.length(); i>0; i-=9)
  14. if (i < 9)
  15. vec1.push_back (atoi (s.substr (0, i).c_str()));
  16. else
  17. vec1.push_back (atoi (s.substr (i-9, 9).c_str()));
  18. return vec1;
  19. }
  20.  
  21. int main()
  22. {
  23. string a, b;
  24. vector<int> vec1;
  25. vector<int> vec2;
  26. cin >> a >> b;
  27. vec1=convert(a);
  28. vec2=convert(b);
  29.  
  30. //for (int i=0; i<vec1.size(); i++)
  31. //cout << vec1[i] << " ";
  32. int carry = 0;
  33. for (size_t i=0; i<max(vec1.size(),vec2.size()) || carry; ++i)
  34. {
  35. if (i == vec1.size())
  36. vec1.push_back (0);
  37. vec1[i] += carry + (i < vec2.size() ? vec2[i] : 0);
  38. carry = vec1[i] >= base;
  39. if (carry) vec1[i] -= base;
  40. }
  41.  
  42. for (int i=vec1.size()-1; i>=0; i--)
  43. cout << vec1[i];
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
Standard output is empty