Game
InterviewTime limit1sMemory limit128 MB
Given many filled 5x5 tic-tac-toe boards, determine for each whether A, B, or neither has three consecutive same marbles in a row, column, or diagonal.
- Level
Easy3 of 10
- Topics
- Matrix, Simulation, Implementation
- Solved
- No attempts yet
Problem
Tic-tac-toe is a favorite way to pass a lazy afternoon in Ardenia. Arthum and Breece are not fans of the game, but their mother told them to play, so they sit down at a 5 × 5 board. Each of them owns a large pile of marbles: Arthum's marbles are marked with an A, and Breece's are marked with a B.
Because they are only two years old, they have no concept of taking turns. Instead, they toss their marbles onto the board as fast as they can, so after a while every one of the 25 fields holds either an A marble or a B marble.
Now they would like to know who won, but counting is not their strong suit either. In tic-tac-toe a player wins by getting three of their own marbles in a row — three consecutive fields lined up horizontally, vertically, or diagonally (in either diagonal direction). A run of more than three marbles also counts, since it contains three consecutive marbles.
- If only Arthum has three marbles in a row, Arthum wins.
- If only Breece has three marbles in a row, Breece wins.
- If both of them have three in a row, or neither of them does, the game is a draw.
The input describes several finished games. The first line contains an integer (), the number of games, followed by the games in the format described below.
Input
The first line contains the number of games . Each game is described by 5 lines, and each of those lines contains exactly 5 characters, each either A or B, describing one 5 × 5 board.
Output
For each game, output a single line containing its result: A wins, B wins, or draw.