|
| 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 | +typedef long long ll; |
| 18 | +#define sz size() |
| 19 | + |
| 20 | +class ValueOfString{ |
| 21 | + public: |
| 22 | + int findValue(string s){ |
| 23 | + int n = s.size(), res = 0; |
| 24 | + for(int i = 0; i < n; i++){ |
| 25 | + int k = 0; |
| 26 | + for(int j = 0; j < n; j++) if(s[j] <= s[i]) k++; |
| 27 | + res += k * (s[i] - 'a' + 1); |
| 28 | + } |
| 29 | + return res; |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | +// BEGIN CUT HERE |
| 34 | + public: |
| 35 | + 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(); } |
| 36 | + private: |
| 37 | + 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(); } |
| 38 | + void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } |
| 39 | + void test_case_0() { string Arg0 = "babca"; int Arg1 = 35; verify_case(0, Arg1, findValue(Arg0)); } |
| 40 | + void test_case_1() { string Arg0 = "zz"; int Arg1 = 104; verify_case(1, Arg1, findValue(Arg0)); } |
| 41 | + void test_case_2() { string Arg0 = "y"; int Arg1 = 25; verify_case(2, Arg1, findValue(Arg0)); } |
| 42 | + void test_case_3() { string Arg0 = "aaabbc"; int Arg1 = 47; verify_case(3, Arg1, findValue(Arg0)); } |
| 43 | + void test_case_4() { string Arg0 = "topcoder"; int Arg1 = 558; verify_case(4, Arg1, findValue(Arg0)); } |
| 44 | + void test_case_5() { string Arg0 = "thequickbrownfoxjumpsoverthelazydog"; int Arg1 = 11187; verify_case(5, Arg1, findValue(Arg0)); } |
| 45 | + void test_case_6() { string Arg0 = "zyxwvutsrqponmlkjihgfedcba"; int Arg1 = 6201; verify_case(6, Arg1, findValue(Arg0)); } |
| 46 | + |
| 47 | +// END CUT HERE |
| 48 | + |
| 49 | +}; |
| 50 | + |
| 51 | +// BEGIN CUT HERE |
| 52 | +int main(){ |
| 53 | + |
| 54 | + ValueOfString ___test; |
| 55 | + ___test.run_test(-1); |
| 56 | +} |
| 57 | +// END CUT HERE |
0 commit comments