Artifact 07a980198f560771d49765546c2e5a5d044d1105
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;
class LeftRightDigitsGame { public:
string minNumber(string digits)
{
string cur, nonzero;
for(int i=0; i<digits.size(); ++i) {
if(digits[i] != '0')
if(!nonzero.empty() && nonzero[0]=='0')
nonzero = digits[i]+cur;
else
nonzero = min(digits[i]+cur, nonzero+digits[i]);
else
nonzero = nonzero+digits[i];
cur = min(cur+digits[i], digits[i]+cur);
}
return nonzero;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, LeftRightDigitsGame().minNumber(digits));}
int main(){
CASE(0)
string digits = "565";
string _ = "556";
END
CASE(1)
string digits = "9876543210";
string _ = "1234567890";
END
CASE(2)
string digits = "8016352";
string _ = "1086352";
END
CASE(3)
string digits = "01";
string _ = "10";
END
/*
CASE(4)
string digits = ;
string _ = ;
END
*/
}
// END CUT HERE