Problem:


三目並べ

 3 &times; 3 の盤面の三目並べを考えましょう。三目並べは 2 人で行う対戦ゲームです。先攻後攻を決め、一人は黒石、一人は白石を打ちます。盤面に石を交互に一つずつ置いていき、縦横斜めのいずれかの方向に先に 3 つ自分の石を並べた人が勝ちとなります。
 

 盤面の情報を入力とし、勝敗の判定を行い、黒が勝ちの場合は「b」、白が勝ちの場合は「w」、どちらもそろっていない場合は「NA」と出力するプログラムを作成してください。 盤面の情報は、3行3列の文字列で構成されます。「b」は黒石、「w」は白石、「+」(半角プラ
ス)は何も置かれていない状況を表します。ただし、同時に黒が3つ、白が3つ並ぶことはありませ
ん。

-->

Input

 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
 各データセットは以下の形式で与えられます。

board1
board2
board3

i 行目に盤面の i 行目の情報を表す文字列 boardi が与えられます。

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

Output

データセット毎に、「b」、「w」、「NA」のいずれかを１行に出力します。

Sample Input

bbw
wbw
+b+
bwb
wbw
wbw
0

Output for the Sample Input

b
NA



Sample input:
bbw
wbw
+b+
bwb
wbw
wbw
0


Sample output:
b
NA

Submission status: Wrong Answer

Solution code:
def f(line):
    if line == ['b','b','b']:
        print 'b'
        return True
    elif line == ['w', 'w', 'w']:
        print 'w'
        return True

while True:
    L = []
    line = raw_input()
    if line == '0': break
    L.append(line)
    for i in range(2):
        L.append(raw_input())
    flag = False
    for line in L:
        if f(line):
            flag = True
            break
    if flag: continue
    for w in range(3):
        if f([L[h][w] for h in range(3)]):
            flag = True
            break
    if flag: continue
    if f([L[i][i] for i in range(3)]): continue
    if not f([L[i][2-i] for i in range(3)]):
        print 'NA'

Submission status: Wrong Answer

Solution code:
import sys
while True:
    Fu = []
    boa = input()
    if boa == "0":
        break
    Fu.append(list(boa))
    for i in range(2):
        boa = list(input())
        Fu.append(boa)
    for i in range(3):
        if Fu[i][0] == Fu[i][1] == Fu[i][2]:
            print(Fu[i][0])
            sys.exit()

        if Fu[0][i] == Fu[1][i] == Fu[2][i]:
            print(Fu[0][i])
            sys.exit()
    if Fu[0][0] == Fu[1][1] == Fu[2][2]:
        print(Fu[0][0])
        sys.exit()
    if Fu[0][2] == Fu[1][1] == Fu[2][0]:
        print(Fu[1][1])
        sys.exit()
    print("NA")

Submission status: Wrong Answer

Solution code:
while True:

    input_data1 = input()

    if input_data1 == "0":
        break

    input_data2 = input()
    input_data3 = input()

    output = "NA"

    if input_data1[0] == input_data1[1] == input_data1[2]:
        output = input_data1[0]
    elif input_data2[0] == input_data2[1] == input_data2[2]:
        output = input_data2[0]
    elif input_data3[0] == input_data3[1] == input_data3[2]:
        output = input_data3[0]

    elif input_data1[0] == input_data2[0] == input_data3[0]:
        output = input_data1[0]
    elif input_data1[1] == input_data2[1] == input_data3[1]:
        output = input_data1[1]
    elif input_data1[2] == input_data2[2] == input_data3[2]:
        output = input_data1[2]

    elif input_data1[0] == input_data2[1] == input_data3[2]:
        output = input_data1[0]
    elif input_data1[2] == input_data2[1] == input_data3[0]:
        output = input_data1[2]

    print(output)

Submission status: Wrong Answer

Solution code:
while True:
    s=raw_input()
    if s=="0":break
    T=[list(s)]+[list(raw_input()) for i in range(2)]
    L1=[T[i][i] for i in range(len(T))]
    L2=[T[i][2-i] for i in range(len(T))]
    for i in range(3):
        if len(set(T[i]))==1:
            print "b" if T[i][0]=="b" else "w"
            break
        if len(set([t[i] for t in T]))==1:
            print "b" if T[0][i]=="b" else "w"
            break
        if len(set(L1))==1 or len(set(L2))==1:
            print "b" if T[1][1]=="b" else "w"
            break
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    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]:
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        f = [list(raw_input()) for _ in xrange(3)]
    except EOFError:
        break
    g = map(lambda x:"".join(x),f+zip(*f))
    print "b" if "b"*3 in g else "w" if "w"*3 in g else "NA"

Submission status: Wrong Answer

Solution code:
while True:
    try:
        f = [list(raw_input()) for _ in xrange(3)]
    except EOFError:
        break
    g = map(lambda x:"".join(x),
            f+zip(*f)+[f[0][0],f[1][1],f[2][2]]+[f[2][0]+f[1][1]+f[0][2]])
    print "b" if "b"*3 in g else "w" if "w"*3 in g else "NA"

Submission status: Wrong Answer

Solution code:
b,w = ["b"]*3,["w"]*3
while 1:
	try:
		board = [list(raw_input()) for i in range(3)]
		ans = "NA"
		for i in range(3):
			if b == board[i] or b == [board[j][i] for j in range(3)]:
				ans = "b"
			elif w == board[i] or w == [board[j][i] for j in range(3)]:
				ans = "w"
		if   b == [board[i][i] for i in range(3)]: ans = "b"
		elif w == [board[i][i] for i in range(3)]: ans = "w"
		print ans
	except:
		break

Submission status: Wrong Answer

Solution code:
b,w = ["b"]*3,["w"]*3
t = range(3)
while 1:
	try:
		bw = [list(raw_input()) for i in t]
		ans = "NA"
		for i in range(3):
			if b == bw[i] or b == [bw[j][i] for j in t]: ans = "b"
			if w == bw[i] or w == [bw[j][i] for j in t]: ans = "w"
		if   b == [bw[i][i] for i in t] or b == [bw[2-i][2-i] for i in t]: ans = "b"
		if w == [bw[i][i] for i in t] or w == [bw[2-i][2-i] for i in t]: ans = "w"
		print ans
	except:
		break

Submission status: Wrong Answer

Solution code:
b,w = ["b"]*3,["w"]*3
t = range(3)
while 1:
	try:
		bw = [list(raw_input()) for i in t]
		ans = "NA"
		for i in range(3):
			if b == bw[i] or b == [bw[j][i] for j in t]: ans = "b"
			if w == bw[i] or w == [bw[j][i] for j in t]: ans = "w"
		if b == [bw[i][i] for i in t] or b == [bw[2-i][2-i] for i in t]: ans = "b"
		if w == [bw[i][i] for i in t] or w == [bw[2-i][2-i] for i in t]: ans = "w"
		print ans
	except:
		break

Submission status: Accepted

Solution code:
def f(line):
    if line == ['b','b','b']:
        print 'b'
        return True
    elif line == ['w', 'w', 'w']:
        print 'w'
        return True

while True:
    L = []
    line = raw_input()
    if line == '0': break
    L.append(list(line))
    for i in range(2):
        L.append(list(raw_input()))
    flag = False
    for line in L:
        if f(line):
            flag = True
            break
    if flag: continue
    for w in range(3):
        if f([L[h][w] for h in range(3)]):
            flag = True
            break
    if flag: continue
    if f([L[i][i] for i in range(3)]): continue
    if not f([L[i][2-i] for i in range(3)]):
        print 'NA'

Submission status: Accepted

Solution code:
def f(a):
    for x in ['b','w']:
        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 'NA'

while 1:
    a=list(input())
    if len(a)==1:break
    a+=list(input())+list(input())
    print(f(a))

Submission status: Accepted

Solution code:
def f(a):
    for x in ['b','w']:
        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 'NA'

while 1:
    a=input()
    if a=='0':break
    a+=input()+input()
    print(f(list(a)))

Submission status: Accepted

Solution code:
def f(a):
    for x in ['b','w']:
        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 'NA'

while 1:
    a=input()
    if a=='0':break
    print(f(a+input()+input()))

Submission status: Accepted

Solution code:
def f(a):
    for x in 'bw':
        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 'NA'

while 1:
    a=input()
    if a =='0':break
    print(f(a+input()+input()))

Submission status: Accepted

Solution code:
def f1(c, l):
    for i in range(3):
        if c*3 == l[i]:
            return 1
    return 0

def f2(c, l):
    for i in range(0, 7, 3):
        s = set(h[i:i+3])
        if c in s and len(s) == 1:
            return 1
    return 0

def f3(c, l):
    if c*3 == l[0]+l[4]+l[8]:
        return 1
    if c*3 == l[2]+l[4]+l[6]:
        return 1
    return 0

while True:
    try:
        w = [input() for _ in range(3)]
    except:
        break
    if f1('b', w):
        print('b')
        continue
    if f1('w', w):
        print('w')
        continue
    h = [w[j][i] for i in range(3) for j in range(3)]
    if f2('b', h):
        print('b')
        continue
    if f2('w', h):
        print('w')
        continue
    if f3('b', h):
        print('b')
        continue
    if f3('w' , h):
        print('w')
        continue
    print("NA")

Submission status: Accepted

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

"""
import sys
from sys import stdin
input = stdin.readline


def solve(board):
    colors = ['b', 'w']
    for c in colors:
        for y in range(3):
            if board[y].count(c) == 3:
                return c
        for x in range(3):
            if board[0][x] == c and board[1][x] == c and board[2][x] == c:
                return c
        if board[0][0] == c and board[1][1] == c and board[2][2] == c:
            return c
        if board[0][2] == c and board[1][1] == c and board[2][0] == c:
            return c
    return 'NA'


def main(args):
    while True:
        temp = input().strip()
        if temp[0] == '0':
            break
        board = []
        board.append(list(temp))
        board.append(list(input().strip()))
        board.append(list(input().strip()))
        result = solve(board)
        print(result)


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

Submission status: Accepted

Solution code:
while True:

    input_data1 = input()

    if input_data1 == "0":
        break

    input_data2 = input()
    input_data3 = input()

    output = "NA"

    if input_data1[0] != "+" and input_data1[0] == input_data1[1] == input_data1[2]:
        output = input_data1[0]
    elif input_data2[0] != "+" and input_data2[0] == input_data2[1] == input_data2[2]:
        output = input_data2[0]
    elif input_data3[0] != "+" and input_data3[0] == input_data3[1] == input_data3[2]:
        output = input_data3[0]

    elif input_data1[0] != "+" and input_data1[0] == input_data2[0] == input_data3[0]:
        output = input_data1[0]
    elif input_data1[1] != "+" and input_data1[1] == input_data2[1] == input_data3[1]:
        output = input_data1[1]
    elif input_data1[2] != "+" and input_data1[2] == input_data2[2] == input_data3[2]:
        output = input_data1[2]

    elif input_data1[0] != "+" and input_data1[0] == input_data2[1] == input_data3[2]:
        output = input_data1[0]
    elif input_data1[2] != "+" and input_data1[2] == input_data2[1] == input_data3[0]:
        output = input_data1[2]

    print(output)

Submission status: Accepted

Solution code:
while True:
    L = input()
    if L == "0":
        break

    table = [["+" for i in range(3)] for j in range(3)]
    for i in range(3):
        table[0][i] = L[i]

    L = input()
    for i in range(3):
        table[1][i] = L[i]

    L = input()
    for i in range(3):
        table[2][i] = L[i]

    ans = "NA"
    for i in range(3):
        if table[0][i] == table[1][i] and table[1][i] == table[2][i] and table[0][i] != "+":
            ans = table[0][i]
            break
        if table[i][0] == table[i][1] and table[i][1] == table[i][2] and table[i][0] != "+":
            ans = table[i][0]
            break
    if table[0][0] == table[1][1] and table[1][1] == table[2][2] and table[0][0] != "+":
        ans = table[0][0]
    if table[2][0] == table[1][1] and table[1][1] == table[0][2] and table[2][0] != "+":
        ans = table[2][0]
    print(ans)

Submission status: Accepted

Solution code:
all_b = "bbb"
all_w = "www"
while True:
  r1 = input()
  if r1 == "0":
    break
  r2 = input()
  r3 = input()
  cands = [r1, r2, r3]
  for i in range(3):
    col = r1[i] + r2[i] + r3[i]
    cands.append(col)
  cands.append(r1[0] + r2[1] + r3[2])
  cands.append(r1[2] + r2[1] + r3[0])
  for cand in cands:
    if cand == all_b:
      print("b")
      break
    elif cand == all_w:
      print("w")
      break
  else:
    print("NA")

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;
while True:
	line = raw_input()
	if line == "0":
		break
	line += raw_input() + raw_input()
	for c in ['b', 'w']:
		if win(c, line):
			print c
			break
	else:
		print 'NA'

Submission status: Accepted

Solution code:
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    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]!="+":
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"

Submission status: Accepted

Solution code:
while True:
    try:
        f = [list(raw_input()) for _ in xrange(3)]
    except EOFError:
        break
    g = map(lambda x:"".join(x),
            f+zip(*f)+[(f[0][0],f[1][1],f[2][2])]+[(f[2][0],f[1][1],f[0][2])])
    print "b" if "b"*3 in g else "w" if "w"*3 in g else "NA"

Submission status: Accepted

Solution code:
while True:
    try:
        f = [list(raw_input()) for _ in xrange(3)]
    except EOFError:
        break
    g = map(lambda x:"".join(x),
            f+zip(*f)+zip(*[(f[i][i],f[2-i][i]) for i in xrange(3)]))
    print "b" if "b"*3 in g else "w" if "w"*3 in g else "NA"

Submission status: Accepted

Solution code:
b,w = ["b"]*3,["w"]*3
t = range(3)
while 1:
	try:
		bw = [list(raw_input()) for i in t]
		ans = "NA"
		for i in range(3):
			if b == bw[i] or b == [bw[j][i] for j in t]: ans = "b"
			if w == bw[i] or w == [bw[j][i] for j in t]: ans = "w"
		if b == [bw[i][i] for i in t] or b == [bw[i][2-i] for i in t]: ans = "b"
		if w == [bw[i][i] for i in t] or w == [bw[i][2-i] for i in t]: ans = "w"
		print ans
	except:
		break

Submission status: Accepted

Solution code:
chk = [
    (1,2,3),
    (4,5,6),
    (7,8,9),
    (1,4,7),
    (2,5,8),
    (3,6,9),
    (1,5,9),
    (3,5,7)
    ]
while True:
    s = "0"
    s += raw_input()
    if s[1]=='0':
        break
    s += raw_input()+raw_input()
    judge = "NA"
    for ch in chk:
        if s[ch[0]]==s[ch[1]]==s[ch[2]]:
            if s[ch[0]]=='b':
                judge = "b"
                break
            elif s[ch[0]]=='w':
                judge = "w"
                break
    print judge

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


table = [[] for row in range(3)]

def check(mark):
    global table

    for row in range(3):
        count = 0;
        for col in range(3):
            if table[row][col] == mark:
                count += 1
        if count == 3:
            return True

    for col in range(3):
        count = 0
        for row in range(3):
            if table[row][col] == mark:
                count += 1
        if count == 3:
            return True

    if table[1][1] == mark and ((table[0][0] == mark and table[2][2] == mark) or
            (table[0][2] == mark and table[2][0] == mark)):
        return True
    else:
        return False


while True:
    input_str = input()
    if input_str[0] == "0":
        break
    table[0] = input_str
    for row in range(1,3):
        table[row] = input()

    black = check("b")
    white = check("w")
    if black == True:
        print("b")
    elif white == True:
        print("w")
    else:
        print("NA")

Submission status: Accepted

Solution code:
while 1:
    board = []
    n = list(input())
    if n[0] == "0":
        break

    board.append(n)
    for _ in range(2):
        n = list(input())
        board.append(n)

    ans = "NA"
    for i in range(3):
        if board[i][0] == board[i][1] == board[i][2] and board[i][0] != "+":
            ans = board[i][0]
        elif board[0][i] == board[1][i] == board[2][i] and board[0][i] != "+":
            ans = board[0][i]

    if board[0][0] == board[1][1] == board[2][2] and board[0][0] != "+":
        ans = board[0][0]
    elif board[2][0] == board[1][1] == board[0][2] and board[2][0] != "+":
        ans = board[1][1]

    print(ans)

Submission status: Accepted

Solution code:
def b_or_w(b_1, b_2, b_3):
    b, w = 'bbb', 'www'
    board = [b_1, b_2, b_3]
    for i in range(3):
        col = b_1[i] + b_2[i] + b_3[i]
        board.append(col)
    board.append(b_1[0] + b_2[1] + b_3[2])
    board.append(b_1[2] + b_2[1] + b_3[0])
    for bod in board:
        if bod == b:
            return 'b'
        elif bod == w:
            return 'w'
    else:
        return 'NA'

while True:
    b_1 = input()
    if b_1 == '0': break
    b_2, b_3 = input(), input()
    print(b_or_w(b_1, b_2, b_3))

Submission status: Runtime Error

Solution code:
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[tupl\
e(range(0,9,4))]+[tuple(range(2,7,2))]
    for i,j,k in L:
        if s[i]==s[j]==s[k]:
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"

Submission status: Runtime Error

Solution code:
while True:
    s=raw_input()
    if s=="0":break
    s+="".join([raw_input() for i in range(2)])
    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]:
            print "b" if s[i]=="b" else "w"
            break
    else:
        print "NA"