Problems
Izabella and Olga are playing a game alternating turns. Izabella plays first.
The game starts with all game pieces arranged in a single row.
The pieces come in two colors: indigo and orange.
During Izabella's turns, she must choose and remove an indigo piece that is
either the leftmost or rightmost piece remaining. During Olga's turns, she must choose and
remove an orange piece that is either the leftmost or rightmost piece remaining. If at any
point one of the players does not have a legal move (possibly because there are no pieces
remaining), that player loses the game, and the other player is awarded
We use an uppercase letter I to represent indigo pieces and
an uppercase letter O
to represent orange pieces. Suppose, for example, that they play with the following
starting board: IOIOOOII.
On her first turn, Izabella can choose to remove either the leftmost or rightmost
pieces, as both are indigo. Suppose she chooses the leftmost. Then, the board
would become OIOOOII. Then, Olga would have no choice but
to remove the new leftmost piece, as the rightmost piece is not orange, leaving
IOOOII. Izabella can choose again, and this time she chooses the
rightmost piece, leaving IOOOI for Olga's turn. At this point,
Olga has no valid move, so Izabella won. Since there are
Each player plays optimally trying to win and to maximize their own score. A player that cannot guarantee a win plays to minimize the opponent's score.
Given the starting board, can you find out who wins and what is their score?
Input
The first line of the input gives the number of test cases, I if the O if it is orange.
Output
For each test case, output one line containing Case #,
where I for Izabella or O for Olga), and
Example
5
IOIOOOII
OIIIIO
IO
IOIOIOI
IOIOIOOIO
Case #1: I 8
Case #2: O 7
Case #3: O 1
Case #4: I 1
Case #5: O 6