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

hide comments
Ranker: 2012-07-16 16:50:17

Remember X can win twice legally!!

Last edit: 2012-07-17 09:35:15
ajax: 2012-06-24 15:09:55

can somebody provide me some test cases i am getting WA even when my output is right on the test cases ..

rishabh: 2011-12-14 15:07:52

SOMEBODY PLEASE GIVE SOME MORE TEST CASES...
I AM GETTING WRONG ANS AGAIN AND AGAIN..

Vishnu Ramesh Maroli: 2011-09-14 13:30:19

why is the second last configuration invalid? .XXX.XOOO

Sandesh: 2011-05-29 07:12:01

got AC in problem TOE1 but here getting WA with the same logic. what's the difference?
EDIT: got AC here also after reading the problem statement carefully. :)"goal is to determine final state of a valid tic-tac-toe game."

Last edit: 2011-05-29 07:39:12
LEC: 2011-01-31 20:43:13

what would be o/p of OO.OX.XXX

Mohamed Maher: 2010-08-03 13:17:25

be sure from
your goal is to determine whether the board configuration represents the possible final state of a valid tic-tac-toe game.

LeppyR64: 2009-11-13 16:12:44

Finally solved this! Read the problem statement carefully.

:D: 2009-10-28 17:23:16

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.

Seshadri R: 2009-10-26 10:01:39

why the last configuration
OOX
XXO
OXO
is invalid?

Last edit: 2009-10-26 10:02:21

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