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.
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”.
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.
Input: XXXOO.XXX XOXOXOXOX OXOXOXOXO XXOOOXXOX XO.OX...X .XXX.XOOO OOXXXOOXO end Output: invalid valid invalid valid valid invalid invalid
got AC in problem TOE1 but here getting WA with the same logic. what's the difference?
what would be o/p of OO.OX.XXX
be sure from
Finally solved this! Read the problem statement carefully.
There are 4 'X' and 5 'O'. It's impossible since the 'X' player starts the game and so there can never be more 'O' that 'X' on the board.
why the last configuration