Skip to content

Commit cfcf569

Browse files
committed
Barclays 200
1 parent 82c2268 commit cfcf569

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

Scoreboard.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
map<char, int> M;
18+
19+
class Scoreboard{
20+
public:
21+
int getScore(string events) {
22+
M['B'] = 1000;
23+
M['b'] = 250;
24+
M['R'] = 50;
25+
M['J'] = 10000;
26+
M['D'] = 20000;
27+
int total = 0;
28+
for(char c : events) total += M[c];
29+
return total;
30+
}
31+
32+
// BEGIN CUT HERE
33+
public:
34+
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(); }
35+
private:
36+
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(); }
37+
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; } }
38+
void test_case_0() { string Arg0 = "BBB"; int Arg1 = 3000; verify_case(0, Arg1, getScore(Arg0)); }
39+
void test_case_1() { string Arg0 = "BbRJD"; int Arg1 = 31300; verify_case(1, Arg1, getScore(Arg0)); }
40+
void test_case_2() { string Arg0 = ""; int Arg1 = 0; verify_case(2, Arg1, getScore(Arg0)); }
41+
42+
// END CUT HERE
43+
44+
};
45+
46+
// BEGIN CUT HERE
47+
int main(){
48+
49+
Scoreboard ___test;
50+
___test.run_test(-1);
51+
}
52+
// END CUT HERE

Scoreboard.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><p>You have been hired by a gaming company that makes pinball machines. They are
2+
currently making a simple and small pinball machine designed for kids' home
3+
use. As the company's newest Pinball Engineer, your job is to make sure that
4+
the right score is displayed on the machine. Players can get points by hitting
5+
bumpers, moving over rollers, or executing a tricky sequence which gets them
6+
the jackpot or double jackpot.</p>
7+
8+
<p>Write a function which returns the correct number of points the player has
9+
earned so far. The input string, events, consists of characters indicating
10+
what has happened:</p>
11+
12+
<ul>
13+
<li>'B' indicates the ball hit a large bumper. This is worth 1,000 points.</li>
14+
<li>'b' indicates the ball hit a small bumper. This is worth 250 points.</li>
15+
<li>'R' indicates the ball went over a roller. This is worth a measly 50 points.</li>
16+
<li>'J' means the player got the jackpot and earns 10,000 points.</li>
17+
<li>'D' means the player got the double jackpot and gets 20,000 points.</li>
18+
</ul>
19+
20+
</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td>Class:</td><td>Scoreboard</td></tr><tr><td>Method:</td><td>getScore</td></tr><tr><td>Parameters:</td><td>string</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int getScore(string events)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td colspan="2"><h3>Limits</h3></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td>Time limit (s):</td><td>2.000</td></tr><tr><td>Memory limit (MB):</td><td>64</td></tr></table></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td>Events will have a length from 0 to 50 characters, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Events will have no characters other than 'B', 'b', 'R', 'J', and 'D'.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td><table><tr><td><pre>&quot;BBB&quot;</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3000</pre></td></tr><tr><td><table><tr><td colspan="2">Three large bumpers, at 1000 points each, is worth 3000 points.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td><table><tr><td><pre>&quot;BbRJD&quot;</pre></td></tr></table></td></tr><tr><td><pre>Returns: 31300</pre></td></tr><tr><td><table><tr><td colspan="2">One of each scoring: B = 1000, b = 250, R = 50, J = 10000, D = 20000 => Total = 31300
21+
</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td><table><tr><td><pre>&quot;&quot;</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0</pre></td></tr><tr><td><table><tr><td colspan="2">Much sadness, as there was no score at all.</td></tr></table></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>

0 commit comments

Comments
 (0)