Statistics

Problem Statement for "Pinball"

Problem Statement

PROBLEM DESCRIPTION

In honor of TopCoder's one-year anniversary, the company has decided to produce
an elaborate pinball machine, which TopCoder representatives will take with
them to collegiate recruiting events.  You have snagged the enviable job of
designing the pinball software, thus fulfilling your dream of being REQUIRED to
play video games on the job.

One of the most basic needs of a pinball machine is a scoreboard.  You must
write a method that computes the player's current score, based on the events
reported by the machine's sensors.  Note that since the machine is a recruiting
tool to be used in interviews, the machine will only support one player.  Your
method will return the score of the current game (or most recent game, if no
game is currently in progress) given the events reported in the input string.
Scoring is detailed below.

There are several noteworthy features of the pinball machine.  The first
feature is a bonus multiplier which starts at one when the game begins and can
increase to a maximum of five.  The bonus multiplier is advanced when the ball
hits three flags (represented by T, O, and P) in some order, whereupon the
flags are reset and must all be hit again to advance the multiplier further.
Hitting the same flag more than once before all three are hit does not affect
multiplier advancement.  Thus hitting O,T,T,O,P is equivalent to hitting P,T,O;
both sequences advance the multiplier once and leave all flags reset.

Also note that flag hits do not need to be consecutive; other events can occur
in between the relevant flag hits.  Thus for example, letting B be a bumper hit
and L the loss of a ball, a sequence O,T,T,B,B,B,L,P also advances the bonus
multipler.

There are also five extra ball flags (represented by c, o, d, e, and r).  To
get an extra ball, a player must first hit these flags in some order (as with
the bonus multiplier flags, redundant hits are disregarded and flag hits do not
need to be consecutive).  Then the valiant pinballer must seek out the extra
ball target (represented by E).  If this is done, the player is awarded an
extra ball and the extra ball flags are all reset.  Hitting the extra ball
target before all extra ball flags have been hit has no effect.  There is no
limit to the number of extra balls a player can collect during a game.

A player can lose a ball normally (represented by L), whereupon a bonus is
awarded.  If the player loses the ball by tilting the machine (represented by
X), no bonus is awarded.

At the start of a new game:
- The player's score is set to zero.
- All bonus multiplier flags are reset.
- All extra ball flags are reset.
- The bonus multiplier is set to one.
- The player is initially given three balls.

The bonus multiplier flags, bonus multiplier, and extra ball flags are NOT
reset between balls (unless the game has ended).

The input string represents a series of events.  Each event consists of one
character, the interpretation of which are as follows:

B - Ball hit a big bumper.  Player is awarded 1000 * (bonus multiplier) points.
b - Ball hit a little bumper.  Player is awarded 250 * (bonus multiplier) points.
T,O,P - Ball hit the corresponding bonus multiplier flag.
c,o,d,e,r - Ball hit the corresponding extra ball flag.
E - Ball hit the extra ball target.
L - Player lost a ball normally; bonus awarded of 10000 * (bonus multiplier)
points.
X - Player lost a ball by tilting the machine; no bonus awarded.

No other characters will be in the input string.

DEFINITION

Class:  Pinball
Method name:  getScore
Parameters:  String
Returns:  int
Method signature (be sure your method is public):  int getScore(String events)

NOTES

Topcoder will ensure that the input string:
- Has length of between 0 and 50 characters, inclusive.
- Only contains the characters 'B', 'b', 'T', 'O', 'P', 'c', 'o', 'd', 'e',
'r', 'E', 'L', and 'X'.

If the input string is empty, return zero.  

Note that the input string can contain multiple games; there is no special
delineation for a new game, which must rather be inferred from the existence of
an additional event after the player loses the final ball.

EXAMPLES

getScore("BLL") = 21000 (game in progress)
getScore("BLLL") = 31000 (game just concluded)
getScore("BLLLb") = 250 (new game in progress)
getScore("OOTPbL") = 20500 (don't forget the bonus multiplier)
getScore("coderLLLL") = 10000 (no extra ball so we're on the second game)
getScore("coderELLLL") = 40000 (first game just concluded)

Definition

Class:
Pinball
Method:
getScore
Parameters:
String
Returns:
int
Method signature:
int getScore(String param0)
(be sure your method is public)

Constraints

    Examples


      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)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: