File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ grid = ["" for _ in range (9 )]
3+
4+ for case in range (int (input ())):
5+ i = 0
6+ for _ in range (3 ):
7+ for cell in input ():
8+ grid [i ] = cell
9+ i += 1
10+
11+ try : input ()
12+ except : pass # No empty lne after test case
13+
14+ wins = {
15+ "O" : False ,
16+ "X" : False ,
17+ "." : None
18+ }
19+
20+ # Horiz
21+ for i in range (0 , 7 , 3 ):
22+ if grid [i ]== grid [i + 1 ]== grid [i + 2 ]:
23+ wins [grid [i ]] = True
24+
25+ # Vertical
26+ for i in range (3 ):
27+ if grid [i ]== grid [i + 3 ]== grid [i + 6 ]:
28+ wins [grid [i ]] = True
29+
30+ # Diag
31+ if grid [0 ]== grid [4 ]== grid [8 ]:
32+ wins [grid [0 ]] = True
33+
34+ if grid [2 ]== grid [4 ]== grid [6 ]:
35+ wins [grid [2 ]] = True
36+
37+ # X wins
38+ if wins ["X" ] and not wins ["O" ] and grid .count ("X" )== grid .count ("O" )+ 1 :
39+ print ("yes" )
40+
41+ # X loses
42+ elif not wins ["X" ] and wins ["O" ] and grid .count ("X" )== grid .count ("O" ):
43+ print ("yes" )
44+
45+ # Undecided
46+ elif wins ["X" ]== wins ["O" ]== False and 0 <= grid .count ("X" )- grid .count ("O" )<= 1 :
47+ print ("yes" )
48+
49+ else :
50+ print ("no" )
You can’t perform that action at this time.
0 commit comments