Skip to content

Instantly share code, notes, and snippets.

@zhrkvl
Created December 5, 2016 07:08
Show Gist options
  • Save zhrkvl/1dccab4b9cf9a1d9580f81db9e2f3576 to your computer and use it in GitHub Desktop.
Save zhrkvl/1dccab4b9cf9a1d9580f81db9e2f3576 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define INF (1<<30)
#define INFll (1ll<<62)
#define F first
#define S second
#define MOD 1000000007
#define mkp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(I, A, B) for(int (I) = (A); (I) < (B); (I)++)
#define ROF(I, A, B) for(int (I) = (A); (I) >= (B); (I)--)
#define SQR(A) 1ll*(A)*(A)
const char array_sep[] = " ";
const char array_end[] = "";
const char pair_sep[] = " ";
const char pair_end[] = "";
const char map_sep[] = "->";
const char map_end[] = "\n";
//const int dx[] = {-1, 0, 1, 0};
//const int dy[] = {0, 1, 0, -1};
const int dx[] = {0, 1};
const int dy[] = {1, 0};
const int ddx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};
template<typename A> ostream & operator<<(ostream & os, const vector<A> & x)
{
for(int i = 0; i < x.size(); i++)
os << x[i] << array_sep;
os << array_end;
return os;
}
template<typename A> ostream & operator<<(ostream & os, const set<A> & x)
{
for(auto& y: x)
os << y << " ";
return os;
}
template<typename A, typename B> ostream & operator<<(ostream & os, const pair<A, B> & x)
{
os << x.first << pair_sep << x.second << pair_end;
return os;
}
template<typename A> istream & operator>>(istream & is, vector<A> & x)
{
for(int i = 0; i < x.size(); i++)
is >> x[i];
return is;
}
template<typename A, typename B> istream & operator>>(istream & is, pair<A, B> & x)
{
is >> x.first >> x.second;
return is;
}
template<typename _key, typename _val> ostream & operator<<(ostream & os, map<_key, _val> & mp)
{
os << "{\n";
for(auto it : mp) // not for C++98 or earlier
os << "\t" << it.F << map_sep << it.S << map_end;
os << "}\n";
return os;
}
template<typename _response> void die(_response ans)
{
cout << ans << endl;
exit(0);
}
class segtree
{
public:
int n;
vector<int > t;
int query(int l, int r)
{
int res = 0;
for(l += n, r += n; l < r; l >>= 1, r >>= 1)
{
if(l & 1)
res = max(res, t[l++]);
if(r & 1)
res = max(res, t[--r]);
}
return res;
}
void modify(int v, int val)
{
for(t[v += n] += val; v > 1; v >>= 1)
t[v >> 1] = max(t[v], t[v ^ 1]);
}
segtree() {}
segtree(int sz) : n(sz), t(vector<int>(sz << 1, 0)) {}
};
int main()
{
// srand((unsigned int) time(0));
ios_base::sync_with_stdio(0);
// cout << fixed << setprecision(8) << endl;
//#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
// freopen("errlog.log", "w", stderr);
//#else
//// freopen("next.in", "r", stdin);
//// freopen("next.out", "w", stdout);
//// freopen("friends.in", "r", stdin);
//#endif
string s;
cin >> s;
string a = s.substr(s.find('=') + 1);
string buf;
vector<int > dat;
for(int i = 0; i < a.size(); i++)
{
if(a[i] == '+')
{
if(buf.size())
dat.push_back(atoi(buf.data()));
buf.clear();
continue;
}
buf += a[i];
}
if(buf.size())
dat.push_back(atoi(buf.data()));
for(int i = dat.size() - 1; i > 0; i--)
{
if(dat[i-1] + 1 <= dat[i] - 1)
{
dat[i]--;
dat[i-1]++;
cout << accumulate(all(dat), 0) << "=";
cout << dat[0];
for(int i = 1; i < dat.size(); i++)
cout << "+" << dat[i];
cout << endl;
exit(0);
}
}
if(dat.size() == 1)
die("No solution");
dat[dat.size() - 2] += dat[dat.size() - 1];
dat.pop_back();
cout << accumulate(all(dat), 0) << "=";
cout << dat[0];
for(int i = 1; i < dat.size(); i++)
cout << "+" << dat[i];
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment