Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem Description
- Baseball scoring program
- Fans of baseball games often keep track of a games progress using scorecards and a set of symbols to represent different plays of a game. For example: a strikeout is traditionally represented by the letter K, and a walked batter is denoted by BB for "Base on Balls". Base Runners score a point if they reach Home (Fourth Base, if you will) before being tagged or forced out.
- You are to write a program which accepts a stream of baseball plays and produces the final score of the game for Team Def (first at bat) and Team Con (second at bat). The set of symbols should produce unambiguous results. In order to avoid ambiguity with regards to Runners' movements, we will restrict the movement of Runners to make them more predictable. See each symbol below for restrictions on Runner movements.
- If you need a refresher on the basic rules of baseball: http://simple.wikipedia.org/wiki/Baseball
- Symbol Table
- Sometimes a symbol table references a position through the use of a number (#). The position to number mapping is as follows:
- 1 - Pitcher
- 2 - Catcher
- 3 - First Base
- 4 - Second Base
- 5 - Third Base
- 6 - Short Stop
- 7 - Left Field
- 8 - Center Field
- 9 - Right Field
- Assume that the Fielder for each position does not relocate to another positions. So if the ball is thrown to the Second Basemen, you may assume that he is standing on Second Base.
- The symbols that will appear in the stream are as follows:
- K - Strikeout
- BB - Base on Balls. Batter advances to first, Runners advance one base
- only if necessary.
- HR - Home Run. All Runners score.
- B1 - Single. Runners advance one base.
- B2 - Double. Runners advance two bases.
- B3 - Triple. Runners advance three bases.
- Each of the preceding 3 symbols may be followed by one of the following two symbols, denoting how the Fielding team responded to the batters hit. Assume that base runners who are not forced out on their way to their "first" base (sequentially ahead, that is) then they successfully progress the correct number of bases. For example, if the Batter hits a triple with Runners on First and Second base, and a Fly Ball is caught then thrown to First, the Batter is Out, the Runner who was originally on First is Out, and the Runner who was originally on Second progresses three bases to Score. This rule may lead to some silly situations but it's MY problem and I'll make Baseball as silly as I want it to be.
- F#+ - Fly ball caught by Fielder then potentially thrown for more outs.
- Assume that if a base is listed and a Runner could be thrown out by
- the ball then the Runner is thrown out. So if a Runner _was_ on
- first base and the throw chain includes first base, the Runner on
- first base is a terrible Runner and has been thrown out before he
- could get back to his base
- L#+ - Ground ball thrown through Fielder chain. Assume that if a base is
- listed and a Runner could be forced out by that Fielder then the
- Runner is forced out. So if a Runner _was_ on first base and the
- throw chain includes second base, then the Runner who was on first
- base is now thrown out. Note that in order for a Runner to be forced
- out all bases behind the forced Runner must be occupied (or about to
- be so). Our fieldsmen haven't yet learned how to tag a Runner out.
- SB# - Stolen base. # is the position that the Runner was originally on.
- Runner advances to next position. Runners will never steal a base
- that is occupied.
- CS# - Caught Stealing. Runner who occupied position # tried to steal a base
- and failed.
- HBP - Batter hit by pitch.
- Sample Input / Output
- Input:
- KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKHRK
- Output:
- Def - 0
- Con - 1
- Home
Advertisement
Add Comment
Please, Sign In to add comment