1a2a57338c 2012-01-20 kinaba: #include <iostream> 1a2a57338c 2012-01-20 kinaba: #include <sstream> 1a2a57338c 2012-01-20 kinaba: #include <iomanip> 1a2a57338c 2012-01-20 kinaba: #include <vector> 1a2a57338c 2012-01-20 kinaba: #include <string> 1a2a57338c 2012-01-20 kinaba: #include <map> 1a2a57338c 2012-01-20 kinaba: #include <set> 1a2a57338c 2012-01-20 kinaba: #include <algorithm> 1a2a57338c 2012-01-20 kinaba: #include <numeric> 1a2a57338c 2012-01-20 kinaba: #include <iterator> 1a2a57338c 2012-01-20 kinaba: #include <functional> 1a2a57338c 2012-01-20 kinaba: #include <complex> 1a2a57338c 2012-01-20 kinaba: #include <queue> 1a2a57338c 2012-01-20 kinaba: #include <stack> 1a2a57338c 2012-01-20 kinaba: #include <cmath> 1a2a57338c 2012-01-20 kinaba: #include <cassert> 1a2a57338c 2012-01-20 kinaba: #include <cstring> 1a2a57338c 2012-01-20 kinaba: #ifdef __GNUC__ 1a2a57338c 2012-01-20 kinaba: #include <ext/hash_map> 1a2a57338c 2012-01-20 kinaba: #define unordered_map __gnu_cxx::hash_map 1a2a57338c 2012-01-20 kinaba: #else 1a2a57338c 2012-01-20 kinaba: #include <unordered_map> 1a2a57338c 2012-01-20 kinaba: #endif 1a2a57338c 2012-01-20 kinaba: using namespace std; 1a2a57338c 2012-01-20 kinaba: typedef long long LL; 1a2a57338c 2012-01-20 kinaba: typedef complex<double> CMP; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: static string ones[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; 1a2a57338c 2012-01-20 kinaba: static string tens[] = {"", "X", "XX", "XXX", "XL", "L"}; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: class KingSort { public: 1a2a57338c 2012-01-20 kinaba: vector <string> getSortedList(vector <string> kings) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: vector< pair<string,int> > kk; 1a2a57338c 2012-01-20 kinaba: for(int i=0; i<kings.size(); ++i) 1a2a57338c 2012-01-20 kinaba: kk.push_back( parse(kings[i]) ); 1a2a57338c 2012-01-20 kinaba: sort(kk.begin(), kk.end()); 1a2a57338c 2012-01-20 kinaba: for(int i=0; i<kings.size(); ++i) 1a2a57338c 2012-01-20 kinaba: kings[i] = encode(kk[i]); 1a2a57338c 2012-01-20 kinaba: return kings; 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: pair<string, int> parse(const string& s) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: stringstream ss(s); 1a2a57338c 2012-01-20 kinaba: string name, ord; 1a2a57338c 2012-01-20 kinaba: ss >> name >> ord; 1a2a57338c 2012-01-20 kinaba: return make_pair(name, roman(ord)); 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: int roman(const string& s) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: for(int i=0; i<=s.size(); ++i) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: int ti = find(&tens[0], &tens[6], s.substr(0, i)) - &tens[0]; 1a2a57338c 2012-01-20 kinaba: int oi = find(&ones[0], &ones[10], s.substr(i)) - &ones[0]; 1a2a57338c 2012-01-20 kinaba: if( oi == 10 || ti == 6 ) 1a2a57338c 2012-01-20 kinaba: continue; 1a2a57338c 2012-01-20 kinaba: return oi + ti*10; 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: return -99999; 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: string encode(const pair<string,int>& p) 1a2a57338c 2012-01-20 kinaba: { 1a2a57338c 2012-01-20 kinaba: stringstream ss; 1a2a57338c 2012-01-20 kinaba: ss << p.first << " " << tens[p.second/10] << ones[p.second%10]; 1a2a57338c 2012-01-20 kinaba: return ss.str(); 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: }; 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: // BEGIN CUT HERE 1a2a57338c 2012-01-20 kinaba: #include <ctime> 1a2a57338c 2012-01-20 kinaba: double start_time; string timer() 1a2a57338c 2012-01-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1a2a57338c 2012-01-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1a2a57338c 2012-01-20 kinaba: { os << "{ "; 1a2a57338c 2012-01-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1a2a57338c 2012-01-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1a2a57338c 2012-01-20 kinaba: void verify_case(const vector <string>& Expected, const vector <string>& Received) { 1a2a57338c 2012-01-20 kinaba: bool ok = (Expected == Received); 1a2a57338c 2012-01-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1a2a57338c 2012-01-20 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } 1a2a57338c 2012-01-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1a2a57338c 2012-01-20 kinaba: #define END verify_case(_, KingSort().getSortedList(kings));} 1a2a57338c 2012-01-20 kinaba: int main(){ 1a2a57338c 2012-01-20 kinaba: 1a2a57338c 2012-01-20 kinaba: CASE(0) 1a2a57338c 2012-01-20 kinaba: string kings_[] = {"Louis IX", "Louis VIII"}; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = {"Louis VIII", "Louis IX" }; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(1) 1a2a57338c 2012-01-20 kinaba: string kings_[] = {"Louis IX", "Philippe II"}; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = {"Louis IX", "Philippe II" }; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(2) 1a2a57338c 2012-01-20 kinaba: string kings_[] = {"Richard III", "Richard I", "Richard II"}; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = {"Richard I", "Richard II", "Richard III" }; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(3) 1a2a57338c 2012-01-20 kinaba: string kings_[] = {"John X", "John I", "John L", "John V"}; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = {"John I", "John V", "John X", "John L" }; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(4) 1a2a57338c 2012-01-20 kinaba: string kings_[] = {"Philippe VI", "Jean II", "Charles V", "Charles VI", "Charles VII", "Louis XI"}; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = {"Charles V", "Charles VI", "Charles VII", "Jean II", "Louis XI", "Philippe VI" }; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(5) 1a2a57338c 2012-01-20 kinaba: string kings_[] = {"Philippe II", "Philip II"}; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = {"Philip II", "Philippe II" }; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: /* 1a2a57338c 2012-01-20 kinaba: CASE(6) 1a2a57338c 2012-01-20 kinaba: string kings_[] = ; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = ; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: CASE(7) 1a2a57338c 2012-01-20 kinaba: string kings_[] = ; 1a2a57338c 2012-01-20 kinaba: vector <string> kings(kings_, kings_+sizeof(kings_)/sizeof(*kings_)); 1a2a57338c 2012-01-20 kinaba: string __[] = ; 1a2a57338c 2012-01-20 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); 1a2a57338c 2012-01-20 kinaba: END 1a2a57338c 2012-01-20 kinaba: */ 1a2a57338c 2012-01-20 kinaba: } 1a2a57338c 2012-01-20 kinaba: // END CUT HERE