Problem:


三目並べ

三目並べは，３ &times; ３のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです（図1〜図3 を参照）

図１：○の勝ち
図２：× の勝ち
図３：引き分け

三目並べは、○と×が交互にマス目を埋めていき、どちらかが一列揃ったときにゲーム終了となります。そのため、図 4 のように、○と×が両方とも一列そろっている場合はありえない局面です。ありえない局面が入力されることはありません。

図４：ありえない局面

三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。

Input

入力は複数のデータセットからなります。各データセットとして、盤面を表す１つの文字列が１行に与えられます。
盤面の文字列は、○、×、空白をそれぞれ半角英小文字の o、x、s であらわし、下図のマス目の順に並んでいます。

データセットの数は 50 を超えません。

Output

データセットごとに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、引き分けならば半角英小文字の d を１行に出力してください。

Sample Input

ooosxssxs
xoosxsosx
ooxxxooxo

Output for the Sample Input

o
x
d



Sample input:
ooosxssxs
xoosxsosx
ooxxxooxo


Sample output:
o
x
d

Submission status: Wrong Answer

Solution code:
ls = ["o","x"]
while True:
    try:
        a = raw_input()
        flag = 1
        for c in ls:
            if a[::4] == c*3 or a[2:8:2] == c*3:
                print c
                flag = 1
            else:
                for i in range(3):
                    if a[3*i:3*(i+1)] == c*3 or a[i::3] == c*3:
                        print c
                        flag = 1
            if flag == 1:
                break
        if flag == 0:
            print "d"
    except:
        break

Submission status: Accepted

Solution code:
import sys
line = ((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6))
for s in map(lambda s: s.rstrip(), sys.stdin):
    for l in line:
        ls = list(set(s[i] for i in l))
        if len(ls) == 1 and ls[0] != "s":
            print(ls[0])
            break
    else:
        print("d")

Submission status: Accepted

Solution code:
def marubatu():
    N=list(input())
    for koma in ["o","x"]:
        for i in range(3):
            if N[i:9:3].count(koma)==3 or N[3*i:3*i+3].count(koma)==3:return koma
        if N[0:9:4].count(koma)==3 or N[2:7:2].count(koma)==3:return koma
    return "d"
while 1:
    try:print(marubatu())
    except:break

Submission status: Accepted

Solution code:
judge = [
        [0, 1, 2], [3, 4, 5], [6, 7, 8],
        [0, 3, 6], [1, 4, 7], [2, 5, 8],
        [0, 4, 8], [2, 4, 6]
        ]

while True:
    try:
        n = list(input())
        ans = None
        for j in judge:
            if n[j[0]] == n[j[1]] == n[j[2]]:
                if n[j[0]] == 's':
                    continue
                else:
                    ans = n[j[0]]
                    break
        if ans:
            print(ans)
        else:
            print('d')
    except:
        break

Submission status: Accepted

Solution code:
import sys

for s in sys.stdin:
    s = s[:-1]
    if s[::4] == "ooo" : print "o"; continue
    if s[::4] == "xxx" : print "x"; continue
    if s[2:8:2] == "ooo" : print "o"; continue
    if s[2:8:2] == "xxx" : print "x"; continue
    if s[0::3] == "ooo" : print "o"; continue
    if s[0::3] == "xxx" : print "x"; continue
    if s[0:3] == "ooo" : print "o"; continue
    if s[0:3] == "xxx" : print "x"; continue
    if s[3:6] == "ooo" : print "o"; continue
    if s[3:6] == "xxx" : print "x"; continue
    if s[6:9] == "ooo" : print "o"; continue
    if s[6:9] == "xxx" : print "x"; continue
    if s[0::3] == "ooo" : print "o"; continue
    if s[0::3] == "xxx" : print "x"; continue
    if s[1::3] == "ooo" : print "o"; continue
    if s[1::3] == "xxx" : print "x"; continue
    if s[2::3] == "ooo" : print "o"; continue
    if s[2::3] == "xxx" : print "x"; continue
    print "d"

Submission status: Accepted

Solution code:
import sys
f = sys.stdin


vlines = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

for line in f:
    result = 'd'
    for v in vlines:
        if 's' !=  line[v[0]] and line[v[0]]== line[v[1]] == line[v[2]]:
            result = line[v[0]]
            break
    print(result)

Submission status: Accepted

Solution code:
def aaa(O, X):
    if O == 3:
        print 'o'
        return True
    elif X == 3:
        print 'x'
        return True

while True:
    try:
        line = raw_input()
        ttt = []
        while line:
            lis = []
            for i in range(3):
                lis.append(line[i])
            else:
                ttt.append(lis)
            line = line[3:]
            
        flag = False
        for y in range(3):
            O = 0
            X = 0
            for x in range(3):
                if ttt[y][x] == 'o':
                    O += 1
                elif ttt[y][x] == 'x':
                    X += 1
            else:
                if aaa(O, X): flag = True
            if flag == True: break
        if flag == True: continue
        
        for x in range(3):
            O = 0
            X = 0
            for y in range(3):
                if ttt[y][x] == 'o':
                    O += 1
                elif ttt[y][x] == 'x':
                    X += 1
            else:
                if aaa(O, X): flag = True
            if flag == True: break
        if flag == True: continue
                
        O = 0
        X = 0
        for i in range(3):
            if ttt[i][i] == 'o':
                O += 1
            elif ttt[i][i] == 'x':
                X += 1
        else:
            if aaa(O, X): flag = True
        if flag == True: continue
            
        O = 0
        X = 0
        for i in range(3):
            if ttt[i][2-i] == 'o':
                O += 1
            elif ttt[i][2-i] == 'x':
                X += 1
        else:
            if aaa(O, X): flag = True
        if flag == True:
            continue
        else:
            print 'd'
    except EOFError:
        break

Submission status: Accepted

Solution code:
while True:
	try:
		n = str(raw_input())
	except EOFError:
		break
	
	if n[0:3] == "ooo" or n[3:6] == "ooo" or n[6:9] == "ooo" or n[0:1]+n[3:4]+n[6:7] == "ooo" or n[1:2]+n[4:5]+n[7:8] == "ooo" or n[2:3]+n[5:6]+n[8:9] == "ooo" or n[0:1]+n[4:5]+n[8:9] == "ooo" or n[2:3]+n[4:5]+n[6:7] == "ooo":
		print "o"
		
	elif n[0:3] == "xxx" or n[3:6] == "xxx" or n[6:9] == "xxx" or n[0:1]+n[3:4]+n[6:7] == "xxx" or n[1:2]+n[4:5]+n[7:8] == "xxx" or n[2:3]+n[5:6]+n[8:9] == "xxx" or n[0:1]+n[4:5]+n[8:9] == "xxx" or n[2:3]+n[4:5]+n[6:7] == "xxx":
		print "x"
		
	else:
		print "d"

Submission status: Accepted

Solution code:
import sys
for line in sys.stdin.readlines():
  l = [s for s in line.rstrip()]
  answer = 'd'
  for i in range(3):
    if l[i] == l[i+3] == l[i+6]:
      if l[i] == 'o':
        answer = 'o'
      elif l[i] == 'x':
        answer = 'x'
  for i in range(0,8,3):
    if l[i] == l[i+1] == l[i+2]:
      if l[i] == 'o':
        answer = 'o'
      elif l[i] == 'x':
        answer = 'x'
  if l[0] == l[4] == l[8] or l[2] == l[4] == l[6]:
    if l[4] == 'o':
      answer = 'o'
    elif l[4] == 'x':
      answer = 'x'
  print(answer)

Submission status: Accepted

Solution code:
def sol(a):
    if len(set(a))==1:
        tmp=a.pop()
        if tmp=='s':
            return ''
        else:
            return tmp
    else:
        return ''
while 1:
    try:
        n=raw_input()
        f=1 
        for i in range(0,7,3):
            if sol(list(n[i:i+3])):
                print sol(list(n[i:i+3]))
                f=0
        for i in range(3):
            if sol(list(n[i]+n[i+3]+n[i+6])):
                print sol(list(n[i]+n[i+3]+n[i+6]))
                f=0
        if f and (sol(list(n[0]+n[4]+n[8])) or sol(list(n[2]+n[4]+n[6]))):
            print sol(list(n[0]+n[4]+n[8]))+sol(list(n[2]+n[4]+n[6]))
            f=0
        if f:
            print 'd'

    except:
        break

Submission status: Accepted

Solution code:
import sys

lines = sys.stdin.readlines()
for line in lines:
    winner = 'd'
    for i in range(0, 7, 3):
        if (line[i] == line[i+1] and line[i+1] == line[i +2]):
            if line[i] != 's':
                winner = line[i]
                
    for i in range(0, 3):
        if (line[i] == line[i+3] and line[i+3] == line[i+6]):
            if line[i] != 's':
                winner = line[i]
               
    if ((line[0] == line[4] and line[4] == line[8]) or (line[2] == line[4] and line[4] == line[6])) and line[4] != 'd':
        winner = line[4]
        
    print(winner)

Submission status: Accepted

Solution code:
import sys

def win(A, c):
    if A[1] == A[2] == A[3] == c or A[4] == A[5] == A[6] == c or A[7] == A[8] == A[9] == c:
        return True
    elif A[1] == A[4] == A[7] == c or A[2] == A[5] == A[8] == c or A[3] == A[6] == A[9] == c:
        return True
    elif A[1] == A[5] == A[9] == c or A[3] == A[5] == A[7] == c:
        return True
    else:
        return False

for line in sys.stdin:
    A = ['d']
    for c in line:
        A.append(c)
    if win(A, 'o'):
        print 'o'
    elif win(A, 'x'):
        print 'x'
    else:
        print 'd'

Submission status: Accepted

Solution code:
import sys

[
    print('o' if 'ooo' in b else ('x' if 'xxx' in b else 'd'))
    for b in [
        [
            "".join([l[i] for i in t])
            for t in [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)]
        ]
        for l in (
            list(s.strip())
            for s in sys.stdin
        )
    ]
]

Submission status: Accepted

Solution code:
def check(f):
    for winner in range(2):
        for i in range(3):
            ok=True
            for j in range(3):
                if(f[i][j]!=winner):ok=False
            if ok:
                return winner
        for j in range(3):
            ok=True
            for i in range(3):
                if(f[i][j]!=winner):ok=False
            if ok:
                return winner
        for k in range(1):
            ok=True
            for i in range(3):
                if(f[i][i]!=winner):ok=False
            if ok:
                return winner
        for k in range(1):
            ok=True
            for i in range(3):
                if(f[i][2-i]!=winner):ok=False
            if ok:
                return winner
    return -1


while True:
    try:
        st=input()
        f=[[-1 for i in range(3)]for j in range(3)]
        for i in range(3):
            for j in range(3):
                n=i*3+j
                if(st[n]=='o'):
                    f[i][j]=0
                elif st[n]=='x':
                    f[i][j]=1
                else:
                    f[i][j]=-1
        ans=check(f)
        if(ans==1):
            print('x')
        elif ans==0:
            print('o')
        else:
            print('d')
    except:
        break

Submission status: Accepted

Solution code:
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]]
while True:
    try:
        s = input()
    except EOFError:
        break
    flag = False
    for i in ok:
        if s[i[0]] == s[i[1]] == s[i[2]] and s[i[0]] != 's':
            print(s[i[0]])
            flag = True
            break
    if flag:
        continue
    print("d")

Submission status: Accepted

Solution code:
def f(a):
    for x in ['o','x']:
        if a[0::4].count(x)==3 or a[2:7:2].count(x)==3:return x
        for i in range(3):
            if a[i*3:i*3+3].count(x)==3 or a[i::3].count(x)==3:return x
    return 'd'

while 1:
    try:a=list(input())
    except:break
    print(f(a))

Submission status: Accepted

Solution code:
def f(a):
    for x in ['o','x']:
        if a[0::4].count(x)==3 or a[2:7:2].count(x)==3:return x
        for i in range(3):
            if a[i*3:i*3+3].count(x)==3 or a[i::3].count(x)==3:return x
    return 'd'

while 1:
    try:print(f(list(input())))
    except:break

Submission status: Accepted

Solution code:
def f(a):
    for x in ['o','x']:
        if a[0::4].count(x)==3 or a[2:7:2].count(x)==3:return x
        for i in range(3):
            if a[i*3:i*3+3].count(x)==3 or a[i::3].count(x)==3:return x
    return 'd'
 
while 1:
    try:print(f(input()))
    except:break

Submission status: Accepted

Solution code:
def f(a):
    for x in 'ox':
        if a[0::4].count(x)==3 or a[2:7:2].count(x)==3:return x
        for i in range(3):
            if a[i*3:i*3+3].count(x)==3 or a[i::3].count(x)==3:return x
    return 'd'

while 1:
    try:print(f(input()))
    except:break

Submission status: Accepted

Solution code:
def judge_aux(t, k):
    found=False
    for i in range(3):
        if t[i] == list(k*3):
            found=True
            break
    if found:
        return(k)

    found=False
    for j in range(3):
        if t[0][j]==t[1][j]==t[2][j]==k:
            found=True
            break
    if found:
        return(k)
        
    if t[0][0] == t[1][1]==t[2][2] == k:
        return(k)
        
    if t[0][2] == t[1][1]==t[2][0] == k:
        return(k)
    
def judge(t):
    if judge_aux(t,"o"):
        return("o")
    elif judge_aux(t,"x"):
        return("x")
    else:
        return("d")

while True:
    try:
        s = list(input().strip())
        t = [[s[3*i+j] for j in range(3)] for i in range(3)]
        print(judge(t))

    except EOFError:
        break

Submission status: Accepted

Solution code:
c = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

while True:
    try:
        S = input()
    except EOFError:
        break
    for i in c:
        o = True
        x = True
        for j in i:
            if S [j] != 'o':
                o = False
            if S [j] != 'x':
                x = False
        if o:
            print('o')
            break
        elif x:
            print('x')
            break
    else:
        print('d')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import re

def is_win(A, B, C, sign):
    if A[0] == A[1] == A[2] == sign or B[0] == B[1] == B[2] == sign or C[0] == C[1] == C[2] == sign:
        return True
    elif A[0] == B[0] == C[0] == sign or A[1] == B[1] == C[1] == sign or A[2] == B[2] == C[2] == sign:
        return True
    elif A[0] == B[1] == C[2] == sign or A[2] == B[1] == C[0] == sign:
        return True
    else:
        return False

for s in sys.stdin:
    s = s.strip()
    A = s[0:3]
    B = s[3:6]
    C = s[6:9]

    if is_win(A, B, C, 'o'):
        print('o')
    elif is_win(A, B, C, 'x'):
        print('x')
    else:
        print('d')

Submission status: Accepted

Solution code:
while True:
    try:
        hoge = input()
    except:
        break
    ans = "d"
    for i in range(3):
        if "ooo" == hoge[i*3:i*3+3] or "ooo" == hoge[i::3]:
            ans = "o"
            break
        elif "xxx" == hoge[i*3:i*3+3] or "xxx" == hoge[i::3]:
            ans = "x"
            break
    if hoge[0::4] == "ooo" or hoge[2:7:2] == "ooo":
        ans = "o"
    elif hoge[0::4] == "xxx" or hoge[2:7:2] == "xxx":
        ans = "x"
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0066
"""
import sys


def prepare_board(size=3):
    return [[1]*size for _ in range(size)]


def check_horizontal(status):
    dp = prepare_board()
    for y in range(len(status)):
        for x in range(1, len(status[0])):
            if status[y][x] == status[y][x-1]:
                dp[y][x] = dp[y][x-1] + 1
                if dp[y][x] == 3:
                    if status[y][x] != 's':
                        return status[y][x]
    return 'd'


def check_vertical(status):
    dp = prepare_board()
    for y in range(1, len(status)):
        for x in range(len(status[0])):
            if status[y][x] == status[y-1][x]:
                dp[y][x] = dp[y-1][x] + 1
                if dp[y][x] == 3:
                    if status[y][x] != 's':
                        return status[y][x]
    return 'd'


def check_diagonal(status):
    # ????????????????????????????§??????????????????§??????
    dp = prepare_board()
    for y in range(1, len(status)):
        for x in range(1, len(status[0])):
            if status[y][x] == status[y-1][x-1]:
                dp[y][x] = dp[y-1][x-1] + 1
                if dp[y][x] == 3:
                    if status[y][x] != 's':
                        return status[y][x]

    # ????????????????????????????§??????????????????§??????
    dp = prepare_board()
    for y in range(1, len(status)):
        for x in range(len(status[0])-2, -1, -1):
            if status[y][x] == status[y-1][x+1]:
                dp[y][x] = dp[y-1][x+1] + 1
                if dp[y][x] == 3:
                    if status[y][x] != 's':
                        return status[y][x]
    return 'd'


def solve(status):
    result = check_horizontal(status)
    if result != 'd':
        return result
    result = check_vertical(status)
    if result != 'd':
        return result
    return check_diagonal(status)


def main(args):
    for line in sys.stdin:
        # ??\???????????????3x3?????¶????????????????????????????§£?????¢??°?????????
        status = []
        line = line.strip()
        status.append(list(line[:3]))
        status.append(list(line[3:6]))
        status.append(list(line[6:]))
        result = solve(status)

        # ?????????????¨?
        print(result)

if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# Aizu Problem 0066: Tic-Tac-Toe
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def check_triple(triple):
    # check whether a triple of values is a winning position:
    return len(set(triple)) == 1 and triple[0] != 's'

    
def isSolved(board):
    # first check if there's a winner:
    # check rows:
    for row in board:
        if check_triple(row):
            return row[0]
    # check columns:
    for col in range(3):
        column = [board[row][col] for row in range(3)]
        if check_triple(column):
            return column[0]
    # check diagonals:
    if check_triple([board[i][i] for i in range(3)]):
        return board[0][0]
    if check_triple([board[i][2-i] for i in range(3)]):
        return board[2][0]
    #
    # no winner:
    return 'd'


for line in sys.stdin:
    string = line.strip()
    board = [string[3*i:3*i+3] for i in range(3)]
    print(isSolved(board))

Submission status: Accepted

Solution code:
import sys
t={'o':1,'x':-1,'s':0}
for l in sys.stdin:
 d=[t[s]for s in l.strip()]
 a=[sum(d[0:3]),sum(d[3:6]),sum(d[6:]),sum(d[0::3]),sum(d[1::3]),sum(d[2::3]),sum(d[0::4]),sum(d[2:8:2])]
 print('o'if 3 in a else'x'if -3 in a else'd')

Submission status: Accepted

Solution code:
import sys
t={'o':1,'x':-1,'s':0}
for l in sys.stdin:
 d=[t[s]for s in l.strip()]
 a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])]
 print('o'if 3 in a else'x'if -3 in a else'd')

Submission status: Accepted

Solution code:
import sys
for l in sys.stdin:
 d=[{'o':1,'x':-1,'s':0}[s]for s in l.strip()]
 a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])]
 print('o'if 3 in a else'x'if -3 in a else'd')

Submission status: Accepted

Solution code:
while True:
    try:
        s = input()
        if s[4] != "s":
            if (s[0] == s[4] and s[0] == s[8]) or (s[2] == s[4] and s[2] == s[6]):
                print(s[4])
                continue
        for i in range(3):
            if s[i] != "s" and s[i] == s[i + 3] and s[i] == s[i + 6]:
                print(s[i])
                break
            elif s[3*i] != "s" and s[3*i] == s[3*i + 1] and s[3*i] == s[3*i + 2]:
                print(s[3*i])
                break
        else:
            print("d")
    except:
        break

Submission status: Accepted

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    table = [[0 for i in range(3)] for j in range(3)]
    S = N[l]
    ans = "d"

    for i in range(9):
        if S[i] == "o":
            table[i // 3][i % 3] = 1
        elif S[i] == "x":
            table[i // 3][i % 3] = -1

    for i in range(3):
        s = 0
        for j in range(3):
            s += table[i][j]
        if s == 3:
            ans = "o"
        elif s == -3:
            ans = "x"

    for i in range(3):
        s = 0
        for j in range(3):
            s += table[j][i]
        if s == 3:
            ans = "o"
        elif s == -3:
            ans = "x"

    s = table[0][0] + table[1][1] + table[2][2]
    if s == 3:
        ans = "o"
    elif s == -3:
        ans = "x"

    s = table[0][2] + table[1][1] + table[2][0]
    if s == 3:
        ans = "o"
    elif s == -3:
        ans = "x"

    print(ans)

Submission status: Accepted

Solution code:
import sys
for l in sys.stdin:
 d=[{'o':1,'x':-1,'s':0}[s]for s in l.strip()]
 a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])]
 print(['dx'[-3 in a],'o'][3 in a])

Submission status: Accepted

Solution code:
import sys
for e in sys.stdin:
 d=[{'o':1,'x':-1,'s':0}[s]for s in e.strip()]
 a=[sum(s)for s in(d[0:3],d[3:6],d[6:],d[0::3],d[1::3],d[2::3],d[0::4],d[2:8:2])]
 print('dxo'[(-3in a)+(3in a)*2])

Submission status: Accepted

Solution code:
def check(s):
  for i in (0, 3, 6): #横
    if s[i] != "s" and s[i] == s[i + 1] and s[i + 1] == s[i + 2]:
      print(s[i])
      return

  for i in (0, 1, 2): #縦
    if s[i] != "s" and s[i] == s[i + 3] and s[i + 3] == s[i + 6]:
      print(s[i])
      return

  if s[0] != "s" and s[0] == s[4] and s[4] == s[8]: #斜め1
      print(s[0])
      return

  if s[2] != "s" and s[2] == s[4] and s[4] == s[6]: #斜め2
      print(s[2])
      return

  print("d")  #それ以外なら引き分け

while True:
  try:
    check(input())

  except EOFError:
    break

Submission status: Accepted

Solution code:
import sys
def ttt(o):
    if (o[0]==o[4]==o[8] or o[2]==o[4]==o[6]) and o[4]!="s":
        return o[4]
    for i in range(3):
        if o[i*3]!="s" and o[i*3]==o[i*3+1]==o[i*3+2]:
            return o[i*3]
        if o[i]!="s" and o[i]==o[i+3]==o[i+6]:
            return o[i]
    return "d"
[print(ttt(j)) for j in [i for i in sys.stdin]]

Submission status: Accepted

Solution code:
# AOJ 0066 Tic Tac Toe
# Python3 2018.6.15 bal4u

arr = [[0 for r in range(3)] for c in range(3)]
koma = { 'o':1, 'x':-1, 's':0 }

while True:
	try: a = list(input())
	except: break
	for i in range(len(a)): arr[i//3][i%3] = koma[a[i]]

	end = False
	for r in range(3):
		d = 0;
		for c in range(3): d += arr[r][c]
		if d == 3 or d == -3:
			end = True
			break
	
	if not end:
		for c in range(3):
			d = 0;
			for r in range(3): d += arr[r][c];
			if d == 3 or d == -3:
				end = True
				break

	if not end:
		d = arr[0][0]+arr[1][1]+arr[2][2]
		if d == 3 or d == -3: end = True
	if not end:
		d = arr[0][2]+arr[1][1]+arr[2][0]

	if d == 3: print('o')
	elif d == -3: print('x')
	else: print('d')

Submission status: Accepted

Solution code:
# AOJ 0066 Tic Tac Toe
# Python3 2018.6.15 bal4u

def check(a):
	for koma in ['o', 'x']:
		for i in range(3):
			if a[i:9:3].count(koma) == 3 or a[3*i:3*i+3].count(koma) == 3: return koma
		if a[0:9:4].count(koma) == 3 or a[2:7:2].count(koma) == 3: return koma
	return 'd'

while True:
	try: print(check(list(input())))
	except EOFError: break

Submission status: Accepted

Solution code:
import sys
def win(c, line):
	for i in range(0, 9, 3):
		if all(p == c for p in line[i:i + 3:1]):
			return True
	for i in range(3):
		if all(p == c for p in line[i:i + 9:3]):
			return True
	if all(p == c for p in line[0::4]): return True
	if all(p == c for p in line[2:8:2]): return True
	return False;
for line in sys.stdin:
	for c in ['o', 'x']:
		if win(c, line):
			print c
			break
	else:
		print 'd'

Submission status: Accepted

Solution code:
import sys
for line in sys.stdin.readlines():
    result="d"
    for i in xrange(3):
        if not line[3*i]=="s" and line[3*i]==line[3*i+1] and line[3*i]==line[3*i+2]:
            result=line[3*i]
        if not line[i]=="s" and line[i]==line[i+3] and line[i]==line[i+6]:
            result=line[i]
    if not line[0]=="s" and line[0]==line[4] and line[0]==line[8]:
        result=line[0]
    if not line[2]=="s" and line[2]==line[4] and line[2]==line[6]:
        result=line[2]
    print result

Submission status: Accepted

Solution code:
while (1):
    try:
        s=raw_input()
    except EOFError:
        break
    B=False
    if s[0]==s[4]==s[8]=="o":
        print "o"
        B=True
    elif s[0]==s[4]==s[8]=="x":
        print "x"
        B=True
    if s[2]==s[4]==s[6]=="o":
        print "o"
        B=True
    elif s[2]==s[4]==s[6]=="x":
        print "x"
        B=True
    for i in range(3):
        if s[i*3]==s[i*3+1]==s[i*3+2]=="o":
            print "o"
            B=True
            break
        elif s[i*3]==s[i*3+1]==s[i*3+2]=="x":
            print "x"
            B=True
            break
        elif s[i]==s[i+3]==s[i+6]=="o":
            print "o"
            B=True
            break
        elif s[i]==s[i+3]==s[i+6]=="x":
            print "x"
            B=True
            break
    if B==False:
        print "d"

Submission status: Accepted

Solution code:
while True:
    try:
        s=raw_input()
    except EOFError:
        break
    L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[(0,4\
,8),(2,4,6)]
    for i,j,k in L:
        if s[i]==s[j]==s[k]!="s":
            print "o" if s[i]=="o" else "x"
            break
    else:
        print "d"

Submission status: Accepted

Solution code:
def get_winner(s):
	for p in ['o','x']:
		for i in xrange(3):
			win_h=True
			win_v=True
			for j in xrange(3):
				if s[i*3+j]!=p:
					win_h=False
				if s[j*3+i]!=p:
					win_v=False
			if win_h or win_v:
				return p
		if p==s[0]==s[4]==s[8] or p==s[2]==s[4]==s[6]:
			return p
	return 'd'

while 1:
	try:
		s=raw_input()
		print get_winner(s)
	except  EOFError:
		break

Submission status: Accepted

Solution code:

import sys


def solv(b):
    if judge(b, 0, 1, 2):
        return b[0]
    elif judge(b, 3, 4, 5):
        return b[3]
    elif judge(b, 6, 7, 8):
        return b[6]
    elif judge(b, 0, 3, 6):
        return b[0]
    elif judge(b, 1, 4, 7):
        return b[1]
    elif judge(b, 2, 5, 8):
        return b[2]
    elif judge(b, 0, 4, 8):
        return b[0]
    elif judge(b, 2, 4, 6):
        return b[2]
    else:
        return 'd'


def judge(b, i, j, k):
    if b[i] == b[j] == b[k] and not b[i] == 's':
        return True
    else:
        return False



for line in sys.stdin:
    boad = list(line.rstrip())
    print solv(boad)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

condition = ('ooo', 'xxx')
for line in stdin:
    if line[0:3] in condition:
        win = line[0]
    elif line[3:6] in condition:
        win = line[3]
    elif line[6:9] in condition:
        win = line[6]
    elif line[0:9:3] in condition:
        win = line[0]
    elif line[1:9:3] in condition:
        win = line[1]
    elif line[2:9:3] in condition:
        win = line[2]
    elif line[0:9:4] in condition:
        win = line[0]
    elif line[2:7:2] in condition:
        win = line[2]
    else:
        win = 'd'
    print(win)

Submission status: Accepted

Solution code:
import sys,itertools
ans = ['xxx      ','   xxx   ','      xxx','x  x  x  ',' x  x  x ','  x  x  x','x   x   x','  x x x  ']
for s in sys.stdin:
	s = s.strip()
	o = [True if c == 'o' else False for c in s]
	x = [True if c == 'x' else False for c in s]
	o = list(itertools.repeat(0,len(ans)))
	x = list(itertools.repeat(0,len(ans)))
	out = 'd'
	for i,j in itertools.product(xrange(len(ans)),xrange(len(ans[0]))):
		if ans[i][j] == 'x':
			if s[j] == 'o':
				o[i] = o[i] + 1
			if s[j] == 'x':
				x[i] = x[i] + 1
	if 3 in o:
		print 'o'
	elif 3 in x:
		print 'x'
	else:
		print 'd'

Submission status: Accepted

Solution code:
import sys
for s in sys.stdin:
    c="d"
    for i in range(3):
        a=s[i]
        if a!="s"and a==s[i+3]==s[i+6]:
            c=a
            break
        j=i*3
        a=s[j]
        if a!="s"and a==s[j+1]==s[j+2]:
            c=a
            break
    else:
        a=s[4]
        if a!="s"and (s[0]==a==s[8] or s[2]==a==s[6]):c=a
    print c

Submission status: Accepted

Solution code:
import sys
x=["ooo","xxx"]
for s in sys.stdin:
    c="d"
    for i in range(3):
        if s[i:9:3]in x:
            c=s[i]
            break
        j=i*3
        if s[j:j+3]in x:
            c=s[j]
            break
    else:
        if s[0::4] in x or s[2:7:2] in x:c=s[4]
    print c

Submission status: Accepted

Solution code:
import sys
def f(a,b,c):
    return a if a!="s"and a==b==c else 0
for s in sys.stdin:
    for i in range(3):
        c=f(*s[i:9:3])
        if c: break
        j=i*3
        c=f(*s[j:j+3])
        if c: break
    else:
        a=s[4]
        if f(*s[0:9:4])or f(*s[2:7:2]):c=a
        else:c="d"
    print c

Submission status: Accepted

Solution code:
import sys
def f(a,b,c):
    return a if a!="s"and a==b==c else 0
for s in sys.stdin:
    for i in range(3):
        c=f(*s[i:9:3])
        if c: break
        j=i*3
        c=f(*s[j:j+3])
        if c: break
    else:
        a=s[4]
        c=a if f(*s[0:9:4])or f(*s[2:7:2]) else "d"
    print c

Submission status: Accepted

Solution code:
import sys
def f(a,b,c):
    return a if a!="s"and a==b==c else 0
for s in sys.stdin:
    for i in range(3):
        c=f(*s[i:9:3])
        if c: break
        j=i*3
        c=f(*s[j:j+3])
        if c: break
    else:
        c=s[4] if f(*s[0:9:4])or f(*s[2:7:2]) else "d"
    print c

Submission status: Accepted

Solution code:
while True:
    try:
        a = raw_input()
        if a[::4] == "ooo" or a[2:8:2] == "ooo":
            print "o"
        elif a[::4] == "xxx" or a[2:8:2] == "xxx":
            print "x"
        else:
            for i in range(3):
                if a[3*i:3*(i+1)] == "ooo" or a[i::3] == "ooo":
                    print "o"
                    break
                elif a[3*i:3*(i+1)] == "xxx" or a[i::3] == "xxx":
                    print "x"
                    break
                elif i == 2:
                    print "d"
    except:
        break

Submission status: Accepted

Solution code:
def judge(a, b, c):
  return a if a == b == c and a != 's' else 0

while True:
  try:
    s = raw_input()
    for i in range(3):
      result = judge(*s[i:9:3])
      if result: break
      result = judge(*s[3*i:3*i+3])
      if result: break
    else:
      result = s[4] if s[4] != 's' and (judge(*s[0:9:4]) or judge(*s[2:7:2])) else 'd'
  except:
    break
  print result

Submission status: Accepted

Solution code:
while True:
    try:
       ban = input()
    except EOFError:
        break

    s = [ban[:3], ban[3:6], ban[6:]]
    s += map(''.join, zip(*s))
    s += [ban[0]+ban[4]+ban[8]] + [ban[2]+ban[4]+ban[6]]

    if 'ooo' in s:
        print('o')
    elif 'xxx' in s:
        print('x')
    else:
        print('d')

Submission status: Accepted

Solution code:
while True:
    try:
        k = list(input())
        ans = 'd'
        lst1 = [k[:3], k[3:6], k[6:]]
        lst2 = [k[::3], k[1::3], k[2::3]]

        if k[4] != 's':
            if k[0] == k[4] and k[4] == k[8]:
                ans = k[4]

            elif k[2] == k[4] and k[4] == k[6]:
                ans = k[4]

        for i in lst1:
            if i.count('o') == 3:
                ans = 'o'
            elif i.count('x') == 3:
                ans = 'x'
            else:
                pass

        for i in lst2:
            if i.count('o') == 3:
                ans = 'o'
            elif i.count('x') == 3:
                ans = 'x'
            else:
                pass

        print(ans)

    except EOFError:
        break