Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool is_digit(char c)
- {
- return (c >= '0' && c <= '9');
- }
- int main()
- {
- vector <int> a;
- string s;
- cin >> s;
- int i, n = s.length(), x = 0, sum = 0;
- for (i = 0; s[i] != '='; i++)
- {
- sum *= 10;
- sum += s[i] - 48;
- }
- for (; i < n; i++)
- {
- if (is_digit(s[i]))
- {
- x *= 10;
- x += s[i] - 48;
- }
- else
- {
- a.push_back(x);
- x = 0;
- }
- }
- a[a.size() - 1]--;
- a[a.size() - 2]++;
- if (a[a.size() - 2] > a[a.size() - 1])
- {
- a[a.size() - 2] += a[a.size() - 1];
- a.pop_back();
- }
- else
- while (a[a.size() - 2] * 2 <= a[a.size() - 1])
- {
- a.push_back(a[a.size() - 1] - a[a.size() - 2]);
- a[a.size() - 2] = a[a.size() - 3];
- }
- cout << sum << "=" << a[0];
- for (i = 1; i < a.size(); i++)
- cout << "+" << a[1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement