Scrabble Scoring
InterviewTime limit1sMemory limit128 MB
Score each Scrabble play by parsing its start square and direction, applying letter and word bonus multipliers from the fixed 15x15 board.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Array, String
- Solved
- No attempts yet
Problem
Scrabble is a word game that has sold over 100 million sets in 121 countries and 29 languages. The game is played by placing tiles, each inscribed with a single letter, onto a board according to simple rules that we will not detail here.
The value of each letter tile is:
The board is a grid of squares. Some squares are premium squares that grant a bonus:
- A letter bonus square multiplies the value of the single tile placed on it:
2Ldoubles that tile's value,3Ltriples it. - A word bonus square multiplies the score of the whole word (after all letter bonuses have been applied):
2Wdoubles the word score,3Wtriples it. If a word covers several word-bonus squares, all of their multipliers are applied.
Rows are numbered 1 to 15 from top to bottom, and columns are labeled A to O from left to right. The premium squares are laid out as follows (.. marks a plain square; the center square H8 counts as a 2W word bonus):
A B C D E F G H I J K L M N O
1 3W .. .. 2L .. .. .. 3W .. .. .. 2L .. .. 3W
2 .. 2W .. .. .. 3L .. .. .. 3L .. .. .. 2W ..
3 .. .. 2W .. .. .. 2L .. 2L .. .. .. 2W .. ..
4 2L .. .. 2W .. .. .. 2L .. .. .. 2W .. .. 2L
5 .. .. .. .. 2W .. .. .. .. .. 2W .. .. .. ..
6 .. 3L .. .. .. 3L .. .. .. 3L .. .. .. 3L ..
7 .. .. 2L .. .. .. 2L .. 2L .. .. .. 2L .. ..
8 3W .. .. 2L .. .. .. 2W .. .. .. 2L .. .. 3W
9 .. .. 2L .. .. .. 2L .. 2L .. .. .. 2L .. ..
10 .. 3L .. .. .. 3L .. .. .. 3L .. .. .. 3L ..
11 .. .. .. .. 2W .. .. .. .. .. 2W .. .. .. ..
12 2L .. .. 2W .. .. .. 2L .. .. .. 2W .. .. 2L
13 .. .. 2W .. .. .. 2L .. 2L .. .. .. 2W .. ..
14 .. 2W .. .. .. 3L .. .. .. 3L .. .. .. 2W ..
15 3W .. .. 2L .. .. .. 3W .. .. .. 2L .. .. 3W
For example, playing BANQUET straight down column O starting at row 1 scores 84: the tile Q lands on a double-letter square and the whole word covers one triple-word square, giving . Playing BANQUETS from the same starting square scores 261, because the extra S also lands on a triple-word square: .
For this problem we ignore tiles already on the board, blank tiles, adjacent tiles, and rack bonuses; simply score each word on its own.
Input
The input consists of a series of lines, each describing one play. Each line begins with the designation of the word's starting position, followed by a single space and then the word itself, a sequence of 2 to 15 uppercase letters.
The starting position is written as a row number and a column letter with no space between them. If the row number comes first (for example 15H), the word is played horizontally, extending to the right. If the column letter comes first (for example O1), the word is played vertically, extending downward. Row numbers range from 1 to 15, and column letters from A to O.
Every word is guaranteed to fit entirely on the board. The list of plays is terminated by a line containing a single #.
Output
For each play in the input, output one line containing the play exactly as given (the starting position, a space, and the word), followed by a space and the score for that play.