Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool is_digit(char c)
  6. {
  7. return (c >= '0' && c <= '9');
  8. }
  9.  
  10. int main()
  11. {
  12. vector <int> a;
  13. string s;
  14. cin >> s;
  15. int i, n = s.length(), x = 0, sum = 0;
  16. for (i = 0; s[i] != '='; i++)
  17. {
  18. sum *= 10;
  19. sum += s[i] - 48;
  20. }
  21. for (; i < n; i++)
  22. {
  23. if (is_digit(s[i]))
  24. {
  25. x *= 10;
  26. x += s[i] - 48;
  27. }
  28. else
  29. {
  30. a.push_back(x);
  31. x = 0;
  32. }
  33. }
  34.  
  35. a[a.size() - 1]--;
  36. a[a.size() - 2]++;
  37. if (a[a.size() - 2] > a[a.size() - 1])
  38. {
  39. a[a.size() - 2] += a[a.size() - 1];
  40. a.pop_back();
  41. }
  42. else
  43. while (a[a.size() - 2] * 2 <= a[a.size() - 1])
  44. {
  45. a.push_back(a[a.size() - 1] - a[a.size() - 2]);
  46. a[a.size() - 2] = a[a.size() - 3];
  47. }
  48. cout << sum << "=" << a[0];
  49. for (i = 1; i < a.size(); i++)
  50. cout << "+" << a[1];
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement