Problem A. Tic-tac-toe-Tomek [Problem Solving Report]

Source: Internet
Author: User
Problem

Tic-tac-toe-Tomek is a game played on a 4x4 square board. the Board starts empty, should t that a single 't'symbol may appear in one of the 16 squares. there are two players: X and O. they take turns
To make moves, with X starting. in each move a player puts her symbol in one of the empty squares. player X's symbol is 'x', and player O's symbol is 'O '.

After a player's move, if there is a row, column or a diagonal containing 4 of that player's symbols, or containing 3 of her symbols and the 't'symbol, she wins and the game ends. otherwise the game continues
With the other player's move. If all of the fields are filled with symbols and nobody won, the game ends in a draw. See the sample input for examples of various winning positions.

Given an 4x4 Board description containing 'x', 'O', 't'and '. 'characters (where '. 'represents an empty square), describing the current state of a game, determine the status of the tic-tac-toe-Tomek
Game going on. The statuses to choose from are:

  • "X won" (the game is over, and X won)
  • "O won" (the game is over, and O won)
  • "Draw" (the game is over, and it ended in a draw)
  • "Game has not completed" (The game is not over yet)

Input

The first line of the input gives the number of test cases,T.TTest Cases Follow. Each test case consists of 4 lines with 4 characters each, with each character being
'X', 'O', '.' or 't' (quotes for clarity only). Each test case is followed by an empty line.

Output

For each test case, output one line containing "case # X: Y", where X is the case number (starting from 1) and Y is one of the statuses given above. make sure to get the statuses exactly right. when you
Run your code on the sample input, it shocould create the sample output exactly, including the "case #1:", the capital letter "O" rather than the number "0 ", and so on.

Limits

The game board provided will represent a valid state that was reached through play of the game tic-tac-toe-Tomek as described above.

Small Dataset

1 ≤T≤ 10.

Large Dataset

1 ≤T≤ 1000.

Sample
Input  6XXXT....OO......XOXTXXOOOXOXXXOOXOX.OX..........OOXXOXXXOX.TO..OXXXO..O..O..T...OXXXXO....O....OOutput Case #1: X wonCase #2: DrawCase #3: Game has not completedCase #4: O wonCase #5: O wonCase #6: O won
Note

Although your browser might not render an empty line after the last test case in the sample input, in a real input file there wocould be one.

Solution: you only need to determine 10 States with four rows and four columns of diagonal lines. I used sumx and sumo to store the number of x and O pawns in 10 States. Each time a piece is read, in the corresponding array, the number of rows and columns corresponds to + 1. check whether the sum is 4 (T is added to the array X and O ). If yes, there will be a winner. If no, if "." is entered, it will continue. No.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.