|
| 1 | +#include <iostream> |
| 2 | +#include <sstream> |
| 3 | +#include <vector> |
| 4 | +#include <algorithm> |
| 5 | +#include <set> |
| 6 | +#include <map> |
| 7 | +#include <queue> |
| 8 | +#include <cstring> |
| 9 | +#include <climits> |
| 10 | +#include <cstdio> |
| 11 | +using namespace std; |
| 12 | +typedef pair<int,int> pi; |
| 13 | +typedef set<int> si; |
| 14 | +typedef vector<int> vi; |
| 15 | +typedef vector<vi> vvi; |
| 16 | +typedef vector<string> vs; |
| 17 | + |
| 18 | +class Scramble{ |
| 19 | + public: |
| 20 | + string scrambleWord(string text) { |
| 21 | + int n = text.size(); |
| 22 | + string startS = string(1, text[0]), endS = string(1, text[n-1]); |
| 23 | + string temp = text.substr(1, n-2); |
| 24 | + sort(temp.begin(), temp.end()); |
| 25 | + int start = 1; |
| 26 | + while(!temp.empty()) { |
| 27 | + string t = string(1, temp[0]); |
| 28 | + if(start) startS += t; |
| 29 | + else endS = t + endS; |
| 30 | + temp = temp.substr(1); |
| 31 | + start = (start + 1)%2; |
| 32 | + } |
| 33 | + return startS + endS; |
| 34 | + } |
| 35 | + |
| 36 | +// BEGIN CUT HERE |
| 37 | + public: |
| 38 | + void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); if ((Case == -1) || (Case == 6)) test_case_6(); } |
| 39 | + private: |
| 40 | + template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } |
| 41 | + void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } |
| 42 | + void test_case_0() { string Arg0 = "alphabet"; string Arg1 = "aaelphbt"; verify_case(0, Arg1, scrambleWord(Arg0)); } |
| 43 | + void test_case_1() { string Arg0 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx"; string Arg1 = "aabcdefghijklmnopqrstuvwyzxwvutsrqponmlkjihgfedcbx"; verify_case(1, Arg1, scrambleWord(Arg0)); } |
| 44 | + void test_case_2() { string Arg0 = "aa"; string Arg1 = "aa"; verify_case(2, Arg1, scrambleWord(Arg0)); } |
| 45 | + void test_case_3() { string Arg0 = "abdfheca"; string Arg1 = "abdfheca"; verify_case(3, Arg1, scrambleWord(Arg0)); } |
| 46 | + void test_case_4() { string Arg0 = "aaaaaaaaa"; string Arg1 = "aaaaaaaaa"; verify_case(4, Arg1, scrambleWord(Arg0)); } |
| 47 | + void test_case_5() { string Arg0 = "uodoutivesbegckw"; string Arg1 = "ubdeiosuvtokgecw"; verify_case(5, Arg1, scrambleWord(Arg0)); } |
| 48 | + void test_case_6() { string Arg0 = "zaabz"; string Arg1 = "zabaz"; verify_case(6, Arg1, scrambleWord(Arg0)); } |
| 49 | + |
| 50 | +// END CUT HERE |
| 51 | + |
| 52 | +}; |
| 53 | + |
| 54 | +// BEGIN CUT HERE |
| 55 | +int main(){ |
| 56 | + |
| 57 | + Scramble ___test; |
| 58 | + ___test.run_test(-1); |
| 59 | +} |
| 60 | +// END CUT HERE |
0 commit comments