cho.sh
Notes
Loading...

Adjacent Mastermind

Time limit

1s

Memory limit

128 MB

Problem

Mastermind is a game about guessing a hidden ordered arrangement of colored pegs. Instead of physical pegs, uppercase letters from A to Z may be used as colors. One player secretly chooses the target arrangement, and another player submits a guess. The player who knows the target must compute the score for the guess.

In this variant, the score is computed in the following order.

  • The black score is the number of positions where the target and guess contain the same letter.
  • The grey score is the number of guess letters not counted as black that can be matched with an unused target letter of the same kind immediately to the left or right.
  • The white score is the number of guess letters not counted as black or grey that can be matched with an unused target letter of the same kind at least two positions away.

Each target letter can be matched at most once, and each guess letter can contribute to at most one score type. First fix the black score, then use the remaining letters to make as many grey matches as possible, and finally use the remaining letters to make as many white matches as possible. For each input line, output the score of the guess.

Input

The input contains several lines. Each line contains a target arrangement and a guess arrangement separated by one space. Each arrangement is a string of length between 2 and 50, inclusive, using uppercase letters from A to Z. On the same line, the target and guess always have the same length.

A line containing only # marks the end of input. Do not process that line.

Output

For each input line containing a target and a guess, output one line. The format is guess: b black, g grey, w white. Here guess is the guess arrangement from the input, and b, g, and w are the black, grey, and white scores.