Under construction

Still being built. Things may change

Scrabble Scoring

Interview

Time limit1sMemory limit128 MB

Summary
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:

ValueLetters
10Q, Z
8J, X
5K
4F, H, V, W, Y
3B, C, M, P
2D, G
1A, E, I, L, N, O, R, S, T, U

The board is a 15×1515 \times 15 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: 2L doubles that tile's value, 3L triples it.
  • A word bonus square multiplies the score of the whole word (after all letter bonuses have been applied): 2W doubles the word score, 3W triples 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 (3+1+1+10×2+1+1+1)×3=84(3+1+1+10 \times 2+1+1+1) \times 3 = 84. Playing BANQUETS from the same starting square scores 261, because the extra S also lands on a triple-word square: (3+1+1+2×10+1+1+1+1)×3×3=261(3+1+1+2 \times 10+1+1+1+1) \times 3 \times 3 = 261.

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.

Examples3

  1. Example 1

    Input
    15H BANQUET
    O1 BANQUETS
    #
    
    Expected output
    15H BANQUET 57
    O1 BANQUETS 261
    
  2. Example 2

    Input
    8E CAT
    #
    
    Expected output
    8E CAT 5
    
  3. Example 3

    Input
    8H OX
    #
    
    Expected output
    8H OX 18