Submit | All submissions | Best solutions | Back to list |
TOE2 - Tic-Tac-Toe ( II ) |
In the game of tic-tac-toe, two players take turns marking squares of an initially empty 3 × 3 grid with either X’s or O’s. The first player always marks squares using X’s, whereas the second player always marks squares using O’s. If at any point during the game either player manages to mark three consecutive squares in a row, column, or diagonal with his/her symbol, the game terminates.
Given a board configuration, your goal is to determine whether the board configuration represents the possible final state of a valid tic-tac-toe game.
Input
The input test file will contain multiple cases. Each test case consists of a single line containing 9 characters, which represent the 9 squares of a tic-tac-toe grid, given one row at a time. Each character on the line will either be ‘X’, ‘O’ (the letter O), or ‘.’ (indicating an unfilled square). The end-of-file is marked by a single line containing the word “end”.
Output
For each input test case, write a single line containing either the word “valid” or “invalid” indicating whether the given board configuration is the final state of some possible tic-tac-toe game.
Example
Input: XXXOO.XXX XOXOXOXOX OXOXOXOXO XXOOOXXOX XO.OX...X .XXX.XOOO OOXXXOOXO end Output: invalid valid invalid valid valid invalid invalid
Added by: | Camilo Andrés Varela León |
Date: | 2006-12-14 |
Time limit: | 0.206s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | Stanford Local 2006 |
hide comments
|
|||||||
2020-12-18 15:37:52
I have handled all the case but still it shows WA <snip> [NG]: Read the footer. Last edit: 2020-12-18 22:26:10 |
|||||||
2020-04-02 16:56:58
first solve TOE1 and then add one if statement. AC in one go........ |
|||||||
2020-03-21 23:03:10
The problem statement is not clear! It didn't mention anything about what to do if the grid is fully filled, should the player who has the turn remove some square mark (i.e. X or O) ? or the game terminates here also ? |
|||||||
2019-11-02 18:15:56
how come a player wins twice in a valid final state?? like the 2nd test case... XOXOXOXOX ???? Last edit: 2019-11-02 18:17:08 |
|||||||
2018-05-27 09:21:29 sharif ullah
Just think about final state of the game,,,like the moment when game will be terminated,,,,not previous termianted && remember 'X' start game && in a game just one player win!! |
|||||||
2015-08-18 06:49:08 SangKuan
this is so bad, the 'final' is not clear.get ac after many wa |
|||||||
2015-06-19 21:45:19 darol
like "i_am_looser" said, 1 more if and same solution from TOE1 pass. |
|||||||
2015-05-24 19:06:02 i_am_looser
One change in TOE1 .................. AC |
|||||||
2014-12-31 16:42:18 agaurav77
150th AC :) |
|||||||
2014-08-18 21:05:24 tapopadma
Guys !! therez a word called "final" in the qn ,,, dont take it light :D |