Check-in [516f62332d]
Not logged in
Overview
SHA1 Hash:516f62332d3a5af3320643f53688a4e4099d579d
Date: 2012-10-10 14:51:48
User: kinaba
Comment:2C practice.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Added SRM/556-U/2C.cpp version [07a980198f560771]

> 1 #include <iostream> > 2 #include <sstream> > 3 #include <iomanip> > 4 #include <vector> > 5 #include <string> > 6 #include <map> > 7 #include <set> > 8 #include <algorithm> > 9 #include <numeric> > 10 #include <iterator> > 11 #include <functional> > 12 #include <complex> > 13 #include <queue> > 14 #include <stack> > 15 #include <cmath> > 16 #include <cassert> > 17 using namespace std; > 18 typedef long long LL; > 19 typedef long double LD; > 20 typedef complex<LD> CMP; > 21 > 22 class LeftRightDigitsGame { public: > 23 string minNumber(string digits) > 24 { > 25 string cur, nonzero; > 26 for(int i=0; i<digits.size(); ++i) { > 27 if(digits[i] != '0') > 28 if(!nonzero.empty() && nonzero[0]=='0') > 29 nonzero = digits[i]+cur; > 30 else > 31 nonzero = min(digits[i]+cur, nonzero+dig > 32 else > 33 nonzero = nonzero+digits[i]; > 34 cur = min(cur+digits[i], digits[i]+cur); > 35 } > 36 return nonzero; > 37 } > 38 }; > 39 > 40 // BEGIN CUT HERE > 41 #include <ctime> > 42 double start_time; string timer() > 43 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) > 44 template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) > 45 { os << "{ "; > 46 for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) > 47 os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return > 48 void verify_case(const string& Expected, const string& Received) { > 49 bool ok = (Expected == Received); > 50 if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() > 51 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' > 52 #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock( > 53 #define END verify_case(_, LeftRightDigitsGame().minNumber(digits));} > 54 int main(){ > 55 > 56 CASE(0) > 57 string digits = "565"; > 58 string _ = "556"; > 59 END > 60 CASE(1) > 61 string digits = "9876543210"; > 62 string _ = "1234567890"; > 63 END > 64 CASE(2) > 65 string digits = "8016352"; > 66 string _ = "1086352"; > 67 END > 68 CASE(3) > 69 string digits = "01"; > 70 string _ = "10"; > 71 END > 72 /* > 73 CASE(4) > 74 string digits = ; > 75 string _ = ; > 76 END > 77 */ > 78 } > 79 // END CUT HERE