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: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
P = [
    (0, 1, 2), (3, 4, 5), (6, 7, 8),
    (0, 3, 6), (1, 4, 7), (2, 5, 8),
    (0, 4, 8), (2, 4, 6),
]
def solve():
    for line in readlines():
        s = line.strip()
        for a, b, c in P:
            if s[a] == s[b] == s[c]:
                if s[a] == 'o':
                    write("o\n")
                    break
                elif s[a] == 'x':
                    write("x\n")
                    break
        else:
            write("d\n")
solve()

Submission status: Accepted

Solution code:
table = [[''] * 3 for i in range(3)]

def ans():
    r = 0
    c = 1
    # 横
    while(r < 3):
        char = table[r][0]
        if char != 's':
            c = 1
            while(c <  3):
                if table[r][c] != char:
                    break
                if table[r][c] == char and c + 1 >= 3:
                    return char
                c += 1
        r += 1
    
    # 縦
    r = 1
    c = 0
    while(c < 3):
        char = table[0][c]
        if char != 's':
            r = 1
            while(r <  3):
                if table[r][c] != char:
                    break
                if table[r][c] == char and r + 1 >= 3:
                    return char
                r += 1
        c += 1
    
    # 斜め
    char = table[1][1]
    if char != 's':
        if (table[0][0] == char and table[2][2] == char) or (table[0][2] == char and table[2][0] == char):
            return char
    return 'd'
    
while(1):
    try:
        s = input()
        for i in range(0,3):
            for j in range(0,3):
                table[i][j] = s[(i * 3) + j]
        print(ans())
    except:
        break

Submission status: Accepted

Solution code:
def cross(s):
    if s[0]==s[4]==s[8] and s[0]!="s":
        print(s[0])
        return True
    elif s[2]==s[4]==s[6] and s[2]!="s":
        print(s[2])
        return True
    else:
        return False

def side(s):
    for i in range(0,len(s),3):
        if s[i]==s[i+1]==s[i+2] and s[i]!="s":
            print(s[i])
            return True
    return False
def ver(s):
    for i in range(3):
        if s[i]==s[i+3]==s[i+6] and s[i]!="s":
            print(s[i])
            return True
    return False


while True:
    try:
        s=list(map(str,input()))               
    except EOFError:
        break
    if cross(s)==side(s)==ver(s)==False:
        print("d")

Submission status: Accepted

Solution code:
while True:
    try:
        s = input().rstrip()
    except:
        break
    win = None
    for i, j, k 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)):
        chk = s[i] + s[j] + s[k]
        if chk == "ooo":
            win = "o"
            break
        elif chk == "xxx":
            win = "x"
            break
    
    if win:
        print(win)
    else:
        print("d")

Submission status: Accepted

Solution code:
def f(s):
    for t in ['o', 'x']:
        if s[::4].count(t) == 3 or s[2:7:2].count(t) == 3:
            return t

        for i in range(3):
            if s[i::3].count(t) == 3 or s[3 * i:3 * i + 3].count(t) == 3:
                return t
    return 'd'


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

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	while True:
		try:
			line = list(input())

			ans = "d"

			if line[0] == "o" and line[4] == "o" and line[8] == "o":
				ans = "o"
			elif line[2] == "o" and line[4] == "o" and line[6] == "o":
				ans = "o"
			elif line[0] == "o" and line[3] == "o" and line[6] == "o":
				ans = "o"
			elif line[1] == "o" and line[4] == "o" and line[7] == "o":
				ans = "o"
			elif line[2] == "o" and line[5] == "o" and line[8] == "o":
				ans = "o"
			elif line[0] == "o" and line[1] == "o" and line[2] == "o":
				ans = "o"
			elif line[3] == "o" and line[4] == "o" and line[5] == "o":
				ans = "o"
			elif line[6] == "o" and line[7] == "o" and line[8] == "o":
				ans = "o"

			if line[0] == "x" and line[4] == "x" and line[8] == "x":
				ans = "x"
			elif line[2] == "x" and line[4] == "x" and line[6] == "x":
				ans = "x"
			elif line[0] == "x" and line[3] == "x" and line[6] == "x":
				ans = "x"
			elif line[1] == "x" and line[4] == "x" and line[7] == "x":
				ans = "x"
			elif line[2] == "x" and line[5] == "x" and line[8] == "x":
				ans = "x"
			elif line[0] == "x" and line[1] == "x" and line[2] == "x":
				ans = "x"
			elif line[3] == "x" and line[4] == "x" and line[5] == "x":
				ans = "x"
			elif line[6] == "x" and line[7] == "x" and line[8] == "x":
				ans = "x"

			print(ans)

		except EOFError:
			break

Submission status: Accepted

Solution code:
while 1:
    try:
        s=input()
        if s[0]==s[1]==s[2]!="s":
            print(s[0])
        elif s[3]==s[4]==s[5]!="s":
            print(s[3])
        elif s[6]==s[7]==s[8]!="s":
            print(s[6])
        elif s[0]==s[3]==s[6]!="s":
            print(s[0])
        elif s[1]==s[4]==s[7]!="s":
            print(s[1])
        elif s[2]==s[5]==s[8]!="s":
            print(s[2])
        elif s[0]==s[4]==s[8]!="s":
            print(s[0])
        elif s[2]==s[4]==s[6]!="s":
            print(s[2])
        else:
            print("d")
    except:break

Submission status: Accepted

Solution code:
while(1):
    try:
        faces = [1 if i == "o" else 0 for i in list(input())]
        hori = [sum(faces[0:3]),sum(faces[3:6]),sum(faces[6:9])]
        vert = [sum(faces[0:7:3]),sum(faces[1:8:3]),sum(faces[2:9:3])]
        diag = [sum(faces[0:9:4]),sum(faces[2:7:2])]
        hori.extend(vert)
        hori.extend(diag)
        if 3 in hori:
            print("o")
        elif 0 in hori:
            print("x")
        else:
            print("d")
    except EOFError:
        break

Submission status: Runtime Error

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:
    print(marubatu())

Submission status: Runtime Error

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' != a and line[v[0]]== line[v[1]] == line[v[2]]:
            result = line[v[0]]
            break
    print(result)

Submission status: Runtime Error

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:
    s = input()
    if len(s) == 0:
        break
    maru = []
    batu = []
    for i in range(9):
        if s[i] == 'o':
            maru.append(i)
        elif s[i] == 'x':
            batu.append(i)
    print(maru, batu)
    flag = False
    for i in ok:
        if i == maru:
            print("o")
            flag = True
            break
        elif i ==batu:
            print("x")
            flag = True
            break
    if not flag:
        print("d")

Submission status: Runtime Error

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:
    s = input()
    if len(s) == 0:
        break
    maru = []
    batu = []
    for i in range(9):
        if s[i] == 'o':
            maru.append(i)
        elif s[i] == 'x':
            batu.append(i)
    flag = False
    for i in ok:
        if i == maru:
            print("o")
            flag = True
            break
        elif i ==batu:
            print("x")
            flag = True
            break
    if not flag:
        print("d")

Submission status: Runtime Error

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:
    s = input()
    if len(s) == 0:
        break
    maru = []
    batu = []
    for i in range(9):
        if s[i] == 'o':
            maru.append(i)
        elif s[i] == 'x':
            batu.append(i)
    flag = False
    for i in ok:
        if i == maru:
            print("o")
            flag = True
            break
        elif i ==batu:
            print("x")
            flag = True
            break
    if flag:
        continue
    print("d")

Submission status: Runtime Error

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:
    s = input()
    if len(s) == 0:
        break
    maru = set()
    batu = set()
    for i in range(9):
        if s[i] == 'o':
            maru.add(i)
        elif s[i] == 'x':
            batu.add(i)
    flag = False
    for i in ok:
        if len(i - maru) == 0:
            print("o")
            flag = True
            break
        elif len(i - batu) == 0:
            print("x")
            flag = True
            break
    if flag:
        continue
    print("d")

Submission status: Runtime Error

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:
    s = input()
    if len(s) == 0:
        break
    flag = False
    for i in ok:
        if s[i[0]] == s[i[1]] == s[i[2]]:
            print(s[i[0]])
            flag = True
    if flag:
        continue
    print("d")

Submission status: Runtime Error

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:
    s = input()
    if len(s) == 0:
        break
    flag = False
    for i in ok:
        if s[i[0]] == s[i[1]] == s[i[2]]:
            print(s[i[0]])
            flag = True
            break
    if flag:
        continue
    print("d")

Submission status: Runtime Error

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:
    s = input()
    if len(s) == 0:
        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: Runtime Error

Solution code:
import sys
board = []
board_list = []
result = []
while 1:
    line = input()
    if not line == "":
        board.append(x)
    else:
        break


def check(num):
    if board_list[num][0] == board_list[num][1] == board_list[num][2]:
        if board_list[num][0] == 'o':
            return 'o'
        elif board_list[num][0] == 'x':
            return 'x'
    if board_list[0][num] == board_list[1][num] == board_list[2][num]:
        if board_list[0][num] == 'o':
            return 'o'
        elif board_list[0][num] == 'x':
            return 'x'
    if board_list[0][0] == board_list[1][1] == board_list[2][2]:
        if board_list[0][0] == 'o':
            return 'o'
        elif board_list[0][0] == 'x':
            return 'x'
    if board_list[0][2] == board_list[1][1] == board_list[2][0]:
        if board_list[0][0] == 'o':
            return 'o'
        elif board_list[0][0] == 'x':
            return 'x'
    return'd'


for i in board:
    board_list = [(a + b + c) for (a, b, c) in zip(i[::3], i[1::3], i[2::3])]
    for j in range(3):
        if check(j) != "d":
            result.append(check(j))
            break
        elif j == 2:
            result.append(check(j))

for i in result:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
board = []
board_list = []
result = []
while 1:
    line = input()
    if not line == "":
        board.append(x)
    else:
        break

except EOFError:
    pass


def check(num):
    if board_list[num][0] == board_list[num][1] == board_list[num][2]:
        if board_list[num][0] == 'o':
            return 'o'
        elif board_list[num][0] == 'x':
            return 'x'
    if board_list[0][num] == board_list[1][num] == board_list[2][num]:
        if board_list[0][num] == 'o':
            return 'o'
        elif board_list[0][num] == 'x':
            return 'x'
    if board_list[0][0] == board_list[1][1] == board_list[2][2]:
        if board_list[0][0] == 'o':
            return 'o'
        elif board_list[0][0] == 'x':
            return 'x'
    if board_list[0][2] == board_list[1][1] == board_list[2][0]:
        if board_list[0][0] == 'o':
            return 'o'
        elif board_list[0][0] == 'x':
            return 'x'
    return'd'


for i in board:
    board_list = [(a + b + c) for (a, b, c) in zip(i[::3], i[1::3], i[2::3])]
    for j in range(3):
        if check(j) != "d":
            result.append(check(j))
            break
        elif j == 2:
            result.append(check(j))

for i in result:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
board = []
board_list = []
result = []
try:
    while 1:
        line = input()
        if not line == "":
            board.append(x)
        else:
            break
except EOFError:
    pass


def check(num):
    if board_list[num][0] == board_list[num][1] == board_list[num][2]:
        if board_list[num][0] == 'o':
            return 'o'
        elif board_list[num][0] == 'x':
            return 'x'
    if board_list[0][num] == board_list[1][num] == board_list[2][num]:
        if board_list[0][num] == 'o':
            return 'o'
        elif board_list[0][num] == 'x':
            return 'x'
    if board_list[0][0] == board_list[1][1] == board_list[2][2]:
        if board_list[0][0] == 'o':
            return 'o'
        elif board_list[0][0] == 'x':
            return 'x'
    if board_list[0][2] == board_list[1][1] == board_list[2][0]:
        if board_list[0][0] == 'o':
            return 'o'
        elif board_list[0][0] == 'x':
            return 'x'
    return'd'


for i in board:
    board_list = [(a + b + c) for (a, b, c) in zip(i[::3], i[1::3], i[2::3])]
    for j in range(3):
        if check(j) != "d":
            result.append(check(j))
            break
        elif j == 2:
            result.append(check(j))

for i in result:
    print(i)

Submission status: Runtime Error

Solution code:
d=0
while True:
  d+=1
  if d==51: break
  s=str(input())
  if s[0]==s[1]==s[2] and s[0] != "s": print(s[0])
  elif s[3]==s[4]==s[5] and s[3] != "s": print(s[3])
  elif s[6]==s[7]==s[8] and s[6] != "s": print(s[6])
  elif s[0]==s[4]==s[8] and s[0] != "s": print(s[0])
  elif s[2]==s[4]==s[6] and s[2] != "s": print(s[2])
  elif s[0]==s[3]==s[6] and s[0] != "s": print(s[0])
  elif s[1]==s[4]==s[7] and s[1] != "s": print(s[1])
  elif s[2]==s[5]==s[8] and s[2] != "s": print(s[2]) 
  else: print("d")

Submission status: Runtime Error

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