Problem:


平面上の図形

縦 8、横 8 のマスからなる図 1 のような平面があります。

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

図１

この平面上に、以下の A から G の図形のどれかが一つだけ置かれています。

	

A

	

		
■■

		
■■

		

		

	

	

B

	

		
■

		
■

		
■

		
■

	

	

C

	

		
■■■■

		

		

		

	

	

D

	

		
■

		
■■

		
■

		

	

	

E

	

		
■■

		
■■

		

		

	

	

F

	

		
■

		
■■

		
■

		

	

	

G

	

		
■■

		
■■

		

		

	

		

たとえば、次の図 2 の例では E の図形が置かれています。

□□□□□□□□

□□□□□□□□

□■■□□□□□

□□■■□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

□□□□□□□□

図２

平面の中で図形が占めているマスを 1、占めていないマスを 0 で表現した数字の列を読み込んで、置かれている図形の種類（A〜G）を出力するプログラムを作成してください。

ただし、ひとつの平面に置かれている図形は必ず１つで、複数の図形が置かれていることはありません。また、A〜G で表される図形以外のものが置かれていることはありません。

Input

入力は複数のデータセットからなります。

１つのデータセットとして、平面の中で図形が占めているマスを 1、占めていないマスを 0 で表現した 8 文字からなる 8 つの文字列が与えられます。例えば、図 2 に対応する文字列の並びは次のようになります。

00000000

00000000

01100000

00110000

00000000

00000000

00000000

00000000

データセットの間は１つの空行で区切られています。データセットの数は 50 を超えません。

Output

各データセットごとに、平面に与えられた図形の種類（A〜G のいずれか）を１行に出力してください。

Sample Input

00000000
00000000
01100000
00110000
00000000
00000000
00000000
00000000

00011110
00000000
00000000
00000000
00000000
00000000
00000000
00000000

00000000
00000000
00110000
00110000
00000000
00000000
00000000
00000000

Output for the Sample Input

E
C
A



Sample input:
00000000
00000000
01100000
00110000
00000000
00000000
00000000
00000000

00011110
00000000
00000000
00000000
00000000
00000000
00000000
00000000

00000000
00000000
00110000
00110000
00000000
00000000
00000000
00000000


Sample output:
E
C
A

Submission status: Accepted

Solution code:
while True:
    try:
        Map = []
        Base = []
        End = []
        for i in range(8):
            Map.append(list(map(str,input())))
        for i in range(8):
            if Base == []:
                
                for j in range(8):
                    if Map[i][j] == '1':
                        Base = [j,i]
                        break
            else:
                break
        for i in range(7,-1,-1):
            if End == []:
                for j in range(7,-1,-1):
                    if Map[i][j] == '1':
                        End = [j,i]
                        break
            else:
                break
        Yoko = End[0] - Base[0]
        Tate = End[1] - Base[1]
        if Tate == 1 and Yoko == 1:
            print("A")
        elif Yoko == 0 and Tate == 3:
            print("B")
        elif Tate == 0 and Yoko == 3:
            print("C")
        elif Yoko == -1 and Tate == 2:
            print("D")
        elif Yoko == 2 and Tate == 1:
            print("E")
        elif Yoko == 1 and Tate == 2:
            print("F")
        elif Tate == 1 and Yoko == 0:
            print("G")
        kara = input()
            
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys


def analyze_figure(data):
    """
    ??????????????????????????§?????????????????£???????????????'1'????????£?????????????????¢??????
    ??????????????¨????????¶??????????????¢??????????????????
    """
    for i, row in enumerate(data):
        if '1' not in row:
            continue
        dot = row.count('1')
        if dot == 1:  # B, D, F???????????????
            x = row.index('1')
            try:
                if data[i+2][x] == '1':
                    return 'B'
                elif data[i+1][x+1] == '1':
                    return 'F'
                else:
                    return 'D'
            except IndexError:
                return None
        else:  # A, C, E, G???????????????
            x = row.index('1')
            try:
                if data[i][x+2] == '1':
                    return 'C'
                elif data[i+1][x] == '0':
                    return 'E'
                elif data[i+1][x+1] == '1':
                    return 'A'
                else:
                    return 'G'
            except IndexError:
                return None


if __name__ == '__main__':
    data = []
    for line in sys.stdin:
        t = line.strip()
        if t:
            t = '00' + t + '00'
            data.append(t)
        # data.append('00000000')
        # data.append('00000000')
        # data.append('00000000')
        # data.append('00000000')
        # data.append('00000000')
        # data.append('00000000')
        # data.append('00000000')
        # data.append('00000000')


        # ???????????????
        if len(data) == 8:
            data.append('000000000000')
            data.append('000000000000')
            ans = analyze_figure(data)

            # ???????????¨???
            if ans:
                print(ans)
            data = []

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
figures = {
    'A': [['1', '1'], ['1', '1']],
    'B': [['1'], ['1'], ['1'], ['1']],
    'C': [['1', '1', '1', '1']],
    'D': [['0', '1'], ['1', '1'], ['1', '0']],
    'E': [['1', '1', '0'], ['0', '1', '1']],
    'F': [['1', '0'], ['1', '1'], ['0', '1']],
    'G': [['0', '1', '1'], ['1', '1', '0']],
}


def f1(lines):
    for n, figure in figures.items():
        found = f2(lines, figure)
        if found:
            print(n)
            break


def f2(lines, figure):
    height = len(figure)
    width = len(figure[0])
    for h in range(8 - height + 1):
        for w in range(8 - width + 1):
            found = f3(lines, figure, height, width, h, w)
            if found:
                return True


def f3(lines, figure, height, width, h, w):
    _figure = [[lines[h+_h][w+_w] for _w in range(width)]
               for _h in range(height)]
    if figure == _figure:
        return True


try:
    while True:
        f1([list(input()) for _ in range(8)])
        input()
except EOFError:
    pass

Submission status: Accepted

Solution code:
def judge(array):
    count = [[0 for i in range(8)] for i in range(8)]
    for i in range(8):
        x = 0
        for j in array[i]:
            if int(j) == 1:
                count[i][x] += 1
            x += 1

    a = 0
    p = []
    for i in range(8):
        for j in range(8):
            if count[i][j] != 0:
                p.append(a)
            a += 1

    if p[0]+1 != p[1]:
        if p[0] + 8*3 == p[3]:
            print('B')
        else:
            if p[0] + 8*2 + 1 == p[3]:
                print('F')
            else:
                print('D')
    else:
        if p[0]+1 == p[1] and p[1]+1 == p[2]:
            print('C')
        else:
            if p[0] + 8 == p[2] and p[1] + 8 == p[3]:
                print('A')
            else:
                if p[0]+8 == p[3]:
                    print('G')
                else:
                    print('E')
                    
while True:
    try:
        array = []
        for i in range(8):
            array.append(input())
        judge(array)
        input()
    except:
        break

Submission status: Accepted

Solution code:
def match(a,b):
    for i in range(len(b)):
        if a == b[i:i+len(a)]:
            return(True)
    return(False)

pat = {'A':[1,1]+[0]*6+[1,1],
       'B':([1]+[0]*7)*3+[1],
       'C':[1]*4,
       'D':[1]+[0]*6+[1,1]+[0]*6+[1],
       'E':[1,1]+[0]*7+[1,1],
       'F':[1]+[0]*7+[1,1]+[0]*7+[1],
       'G':[1,1]+[0]*5+[1,1]}

while True:
    try:
        pla = []
        for _ in range(8):
            l = input().strip()
            pla += map(int,list(l))

        for i in ['A','B','C','D','E','F','G']:
            if match(pat[i],pla):
                print(i)
        input()
    except EOFError:
        break

Submission status: Accepted

Solution code:
N = 8
while True:
    A = []
    for i in range(N):
        A.append(input())

    x1 = -1
    y1 = -1
    for i in range(N):
        for j in range(N):
            if x1 == -1 and A [i] [j] == '1':
                y1 = i
                x1 = j
            elif A [i] [j] == '1':
                y2 = i
                x2 = j

    if x2 - x1 == 1 and y2 - y1 == 1:
        print('A')
    elif x2 - x1 == 0 and y2 - y1 == 3:
        print('B')
    elif x2 - x1 == 3 and y2 - y1 == 0:
        print('C')
    elif x2 - x1 == -1 and y2 - y1 == 2:
        print('D')
    elif x2 - x1 == 2 and y2 - y1 == 1:
        print('E')
    elif x2 - x1 == 1 and y2 - y1 == 2:
        print('F')
    else:
        print('G')
    try:
        input()
    except EOFError:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        figmap = [[0]*12 for _ in range(12)]
        for i in range(8):
            instr = input()
            for j in range(8):
                figmap[i][j+1] = int(instr[j])
        outi = outj = 0
        flag = True
        for i in range(12):
            for j in range(12):
                if figmap[i][j] == 1 and flag:
                    outi = i; outj = j
                    flag = False
        if figmap[outi+1][outj] * figmap[outi][outj+1] * figmap[outi+1][outj+1] == 1: print("A")
        if figmap[outi+1][outj] * figmap[outi+2][outj] * figmap[outi+3][outj] == 1: print("B")
        if figmap[outi][outj+1] * figmap[outi][outj+2] * figmap[outi][outj+3] == 1: print("C")
        if figmap[outi+1][outj] * figmap[outi+1][outj-1] * figmap[outi+2][outj-1] == 1: print("D")
        if figmap[outi][outj+1] * figmap[outi+1][outj+1] * figmap[outi+1][outj+2] == 1: print("E")
        if figmap[outi+1][outj] * figmap[outi+1][outj+1] * figmap[outi+2][outj+1] == 1: print("F")
        if figmap[outi+1][outj] * figmap[outi][outj+1] * figmap[outi+1][outj-1] == 1: print("G")

        input()
    except EOFError: break

Submission status: Accepted

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

import sys
import os

d = {}
d['A'] = ['11', '11']
d['B'] = ['1', '1', '1', '1']
d['C'] = ['1111']
d['D'] = ['01', '11', '10']
d['E'] = ['110', '011']
d['F'] = ['10', '11', '01']
d['G'] = ['011', '110']

DEBUG = False

A = []
for s in sys.stdin:
    s = s.strip()
    if s == '':
        continue

    A.append(s)

    if len(A) == 8:
        # solve
        # ...
        answer = None

        for key in d.keys():
            figure = d[key]
            W = len(figure[0])
            H = len(figure)

            for x in range(8 - W + 1):
                for y in range(8 - H + 1):
                    # check
                    is_fit = True
                    for i, row in enumerate(figure):
                        if not row == A[y+i][x:x+W]:
                            is_fit = False
                            break
                    if is_fit:
                        if DEBUG:
                            print()
                            print('all fit', key)
                            print('A', A)
                            print('x, y', x, y)
                            print('W, H', W, H)
                            print('figure', figure)
                        answer = key
        print(answer)
        A = []

Submission status: Accepted

Solution code:
while True:
    try:
        string = [input() for _ in range(8)]
        string = [int(l) for line in string for l in line] + [0]*32
        one = string.index(1)
        s = string[one:]
        ones = [[1, 8, 9], [8, 16, 24], [1, 2, 3],
                [7, 8, 15], [1, 9, 10], [8, 9, 17], [1, 7, 8]]
        ans = {0: "A", 1: "B", 2: "C", 3: "D", 4: "E", 5: "F", 6: "G"}
        for k, o in enumerate(ones):
            if all([s[o[0]], s[o[1]], s[o[2]]]):
                print(ans[k])
        input()
    except:
        break

Submission status: Accepted

Solution code:
while True : 
    try :
        temp = input()
        if temp == '00000000' or temp == '' : pass
        else :
            if '1111' in temp : print('C')
            else : 
                onetwo, place = temp.count('1'), temp.index('1')
                temp = input()
                if onetwo == 1 :
                    if temp.count('1') == 1 :
                        print('B')
                        input()
                    elif temp.index('1') == place : print('F')
                    else : print('D')
                    input()
                elif onetwo == 2 :
                    if temp.index('1') == place : print('A')
                    elif temp.index('1') == place + 1 : print('E')
                    else : print('G')
    except : break

Submission status: Accepted

Solution code:
Figures = {"A": [[0, 1], [1, 0], [1, 1]],
           "B": [[1, 0], [2, 0], [3, 0]],
           "C": [[0, 1], [0, 2], [0, 3]],
           "D": [[1, -1], [1, 0], [2, -1]],
           "E": [[0, 1], [1, 1], [1, 2]],
           "F": [[1, 0], [1, 1], [2, 1]],
           "G": [[0, 1], [1, -1], [1, 0]]}
while True:
    try:
        k = [map(int, list(input())) for i in range(8)]
        l = [[y, x] for y,q in enumerate(k) for x,t in enumerate(q) if t]
        a, b = l[0]
        for i in range(4):
            l[i][0] -= a
            l[i][1] -= b
        for k, v in Figures.items():
            if l[1:] == v:
                print(k)
                break
        input()
    except:
        break

Submission status: Accepted

Solution code:
import sys
line=[]
in_line=sys.stdin
for _in in in_line:line.append(_in)
#for i in range(89):line.append(input())
sets=(len(line)+1)//9
for i in range(sets):
    flag=0
    topindex=-1
    for j in range(i*9,i*9+9):
        a=line[j].count('1')
        if a!=0:t=line[j].index('1')
        else:t=-1
        if a==4:
            print('C')
            break
        elif flag==0 and a!=0:
            topindex=t
            if a==1:flag=1
            elif a==2:flag=2
        elif flag==1:
            if a==1:
                print('B')
                break
            elif a==2:
                if topindex==t:
                    print('F')
                    break
                else:
                    print('D')
                    break
        elif flag==2:
            if topindex==t:
                print('A')
                break
            elif topindex<t:
                print('E')
                break
            else:
                print('G')
                break

Submission status: Accepted

Solution code:
# Aizu Problem 0036: Figure on Surface
#
import sys, math, os

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


def get_figure(figure):
    for frow in range(8):
        if '1' in figure[frow]:
            fcol = figure[frow].find('1')
            break
    figure = figure[frow:]
    frow = 0
    ones = []
    min_col = 9
    for row in range(len(figure)):
        for col in range(8):
            if figure[row][col] == '1':
                ones.append([row, col])
                min_col = min(min_col, col)
    for k in range(len(ones)):
        ones[k][1] -= min_col
    if ones == [[0, 0], [0, 1], [1, 0], [1, 1]]:
        return 'A'
    elif ones == [[0, 0], [1, 0], [2, 0], [3, 0]]:
        return 'B'
    elif ones == [[0, 0], [0, 1], [0, 2], [0, 3]]:
        return 'C'
    elif ones == [[0, 1], [1, 0], [1, 1], [2, 0]]:
        return 'D'
    elif ones == [[0, 0], [0, 1], [1, 1], [1, 2]]:
        return 'E'
    elif ones == [[0, 0], [1, 0], [1, 1], [2, 1]]:
        return 'F'
    elif ones == [[0, 1], [0, 2], [1, 0], [1, 1]]:
        return 'G'
    else:
        return '?'

    
while True:
    figure = [input().strip() for _ in range(8)]
    print(get_figure(figure))
    try:
        dummy = input()
    except EOFError:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        cnt = 0
        for i in range(8):
            inp = input()
            if cnt == 1:
                if inp.count("1") == 1:
                    print("B")
                elif inp.index("1") == ind:
                    print("F")
                else:
                    print("D")
                cnt = -1
            elif cnt == 2:
                if inp.index("1") == ind:
                    print("A")
                elif inp.index("1") == ind + 1:
                    print("E")
                else:
                    print("G")
                cnt = -1
            elif "1" in inp and cnt == 0:
                ind = inp.index("1")
                cnt = inp.count("1")
                if cnt == 4:
                    print("C")
                    cnt = -1
        inp = input()
    except:
        break

Submission status: Accepted

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

N = list(get_input())
board = [[0 for i in range(11)] for j in range(11)]

for l in range(0, len(N), 9):
    for i in range(l, l+8):
        for j in range(len(N[i])):
            board[i-l][j] = int(N[i][j])
    ans = "X"
    for i in range(8):
        for j in range(8):
            if board[i][j] == 1:
                if board[i+1][j] == 1 and board[i][j+1] == 1 and board[i+1][j+1] == 1:
                    ans = "A"
                elif board[i+1][j] == 1 and board[i+2][j] == 1:
                    ans = "B"
                elif board[i][j+1] == 1 and board[i][j+2] == 1:
                    ans = "C"
                elif board[i][j+1] == 1 and board[i+1][j+1] == 1:
                    ans = "E"
                elif board[i+1][j] == 1 and board[i+1][j+1] == 1:
                    ans = "F"
                elif board[i][j+1] == 1:
                    ans = "G"
                else:
                    ans = "D"
                break
        if ans != "X":
            break
    print(ans)

Submission status: Accepted

Solution code:
while 1:
 a=[list(map(int,input()))for _ in[0]*8]
 y=[sum(r)for r in a]
 x=[sum(c)for c in zip(*a)]
 if 4 in x:print('B')
 elif 4 in y:print('C')
 elif 1 in y:print('DF'[a[y.index(1)][x.index(2)]])
 elif 1 in x:print('GE'[a[y.index(2)][x.index(1)]])
 else:print('A')
 try:input()
 except:break

Submission status: Accepted

Solution code:
while 1:
 a=[list(map(int,input()))for _ in[0]*8]
 y=[sum(r)for r in a]
 x=[sum(c)for c in zip(*a)]
 if 4 in x:s='B'
 elif 4 in y:s='C'
 elif 1 in y:s='DF'[a[y.index(1)][x.index(2)]]
 elif 1 in x:s='GE'[a[y.index(2)][x.index(1)]]
 else:s='A'
 print(s)
 try:input()
 except:break

Submission status: Accepted

Solution code:
while 1:
 a=[list(map(int,input()))for _ in[0]*8]
 y=[sum(r)for r in a]
 x=[sum(c)for c in zip(*a)]
 print('B'if 4 in x else'C'if 4 in y else'DF'[a[y.index(1)][x.index(2)]]if 1 in y else'GE'[a[y.index(2)][x.index(1)]]if 1 in x else'A')
 try:input()
 except:break

Submission status: Accepted

Solution code:
while True:
	try:
		x=[[int(i) for i in input()] for j in range(8)]
		count=0
		num=[]
		for i in range(8):
			if x[i].count(1)!=0:
				num.append(i)
				count+=1
		if count==1:
			print("C")
		elif count==4:
			print("B")
		elif count==2:
			for j in range(8):
				if x[num[0]][j]==1:
					if j==0:
						if x[num[0]+1][j]==1:
							print("A")
						else:
							print("E")
					else:
						if x[num[0]+1][j-1]==1:
							print("G")
						else:
							if x[num[0]+1][j]==1:
								print("A")
							else:
								print("E")
					break
		else:
			for j in range(8):
				if x[num[0]][j]==1:
					if j==0:
						print("F")
					else:
						if x[num[0]+1][j-1]==1:
							print("D")
						else:
							print("F")
					break
		input()
	except EOFError:
		break

Submission status: Accepted

Solution code:
shapes = {
    'A': '1100000011',
    'B': '1000000010000000100000001',
    'C': '1111',
    'D': '01000000110000001',
    'E': '11000000011',
    'F': '100000001100000001',
    'G': '0110000011'
}

while True:
    try:
        plane = ''
        for i in range(8):
            plane += input()

        for name in shapes:
            try:
                plane.index(shapes[name])
                print(name)
                break
            except:
                pass

        input()
    except:
        break

Submission status: Accepted

Solution code:
ans = {"1100000011": "A", "1000000010000000100000001": "B",
       "1111": "C", "1000000110000001": "D",
       "11000000011": "E", "100000001100000001": "F", "110000011": "G"}
while True:
    try:
        st = "".join([input() for _ in range(8)])

        st = st[st.find("1"): st.rfind("1")+1]
        for k, v in ans.items():
            if st == k:
                print(v)
                break
        input()
    except:
        break

Submission status: Accepted

Solution code:
#"1"の座標を、最初のものを(0,0)として切り出し
def trim(mp):
  ret = []

  for x in range(8):
    for y in range(8):
      if mp[y][x] == "1":
        if not ret:
          refer = (x, y)
        ret.append((x, y))

  ret = [(x - refer[0], y - refer[1]) for x, y in ret]
  return ret

#座標が一致したものを出力
def put_ans(points):
  if points == [(0, 0), (0, 1), (1, 0), (1, 1)]: print("A")
  if points == [(0, 0), (0, 1), (0, 2), (0, 3)]: print("B")
  if points == [(0, 0), (1, 0), (2, 0), (3, 0)]: print("C")
  if points == [(0, 0), (0, 1), (1, -1), (1, 0)]: print("D")
  if points == [(0, 0), (1, 0), (1, 1), (2, 1)]: print("E")
  if points == [(0, 0), (0, 1), (1, 1), (1, 2)]: print("F")
  if points == [(0, 0), (1, -1), (1, 0), (2, -1)]: print("G")

while True:
  mp = [input() for _ in range(8)]
  put_ans(trim(mp))
  try:
    input()
  except EOFError:
    break

Submission status: Accepted

Solution code:
t=[{(0,1),(1,0),(1,1)},
   {(1,0),(2,0),(3,0)},
   {(0,1),(0,2),(0,3)},
   {(1,-1),(1,0),(2,-1)},
   {(0,1),(1,1),(1,2)},
   {(1,0),(1,1),(2,1)},
   {(0,1),(1,-1),(1,0)}
]

while 1:
    l=[input() for _ in range(8)]
    pos=sorted([(i,j) for i in range(8) for j in range(8) if l[i][j]=="1"])
    cv=lambda v:tuple([v[0]-pos[0][0],v[1]-pos[0][1]])
    pt=set(map(cv,pos))
    [print(chr(65+i)) for (i,j) in enumerate(t) if pt&j==j]
    try:
        input()
    except:
        break

Submission status: Accepted

Solution code:
# AOJ 0036: A Figure on Surface
# Python3 2018.6.27 bal4u

def judge(sr, sc, tbl):
	if 4 in sr: return 'C'
	if 4 in sc: return 'B'
	if 1 in sr: return 'F' if tbl[sr.index(1)][sc.index(2)] == 1 else 'D'
	if 1 in sc: return 'E' if tbl[sr.index(2)][sc.index(1)] == 1 else 'G'
	return 'A'

tbl = [[] for i in range(8)]
while True:
	for r in range(8): tbl[r] = list(map(int, input()))
	sr, sc = [0]*8, [0]*8
	for i in range(8): sr[i] = sum(tbl[i])
	for i in range(8): sc[i] = sum([tbl[r][i] for r in range(8)])
	print(judge(sr, sc, tbl))
	try: input()
	except: break

Submission status: Accepted

Solution code:
figures = {
    "A": [[1, 1], [1, 1]],
    "B": [[1], [1], [1], [1]],
    "C": [[1, 1, 1, 1]], 
    "D": [[0, 1], [1, 1], [1, 0]],
    "E": [[1, 1, 0], [0, 1, 1]],
    "F": [[1, 0], [1, 1], [0, 1]],
    "G": [[0, 1, 1], [1, 1, 0]]
}

try:
    while True:
        a = [list(map(int, input())) for _ in [0]*8]

        for t, l in figures.items():
            x_size, y_size = len(l[0]), len(l)
            result = False
            for y in range(8-y_size+1):
                for x in range(8-x_size+1):
                    flag = True
                    for dy in range(y_size):
                        for dx in range(x_size):
                            if a[y+dy][x+dx] != l[dy][dx]:
                                flag = False
                    if flag:
                        result = True
                        break
                if result:
                    break
            if result:
                print(t)

        input()

except EOFError:
    exit()

Submission status: Accepted

Solution code:
A="".join(["11000000",
           "11"])

B="".join(["10000000",
           "10000000",
           "10000000",
           "1"])

C="".join(["1111"])

D="".join(["01000000",
           "11000000",
           "1"])

E="".join(["11000000",
           "011"])

F="".join(["10000000",
           "11000000",
           "01"])

G="".join(["01100000",
           "11"])

teto=[A,B,C,D,E,F,G]



while True:
    try:
        a="".join([raw_input() for i in xrange(8)])
        for i in range(len(teto)):
            if a.find(teto[i])>=0:
                print chr(i+ord("A"))
        raw_input()
    except:
        break

Submission status: Accepted

Solution code:
A="".join(["11000000",
           "11"])

B="".join(["10000000",
           "10000000",
           "10000000",
           "1"])

C="".join(["1111"])

D="".join(["01000000",
           "11000000",
           "1"])

E="".join(["11000000",
           "011"])

F="".join(["10000000",
           "11000000",
           "01"])

G="".join(["01100000",
           "11"])

teto=[A,B,C,D,E,F,G]

while True:
    try:
        a="".join([raw_input() for i in xrange(8)])
        for i in range(len(teto)):
            if a.find(teto[i])>=0:
                print chr(i+ord("A"))
        raw_input()
    except:
        break
#temp

Submission status: Accepted

Solution code:
A="".join(["11000000",
           "11"])

B="".join(["10000000",
           "10000000",
           "10000000",
           "1"])

C="".join(["1111"])

D="".join(["01000000",
           "11000000",
           "1"])

E="".join(["11000000",
           "011"])

F="".join(["10000000",
           "11000000",
           "01"])

G="".join(["01100000",
           "11"])

teto=[A,B,C,D,E,F,G]

while True:
    try:
        a="".join([raw_input() for i in xrange(8)])
        for i in range(len(teto)):
            if a.find(teto[i])>=0:
                print chr(i+ord("A"))
        raw_input()
    except:
        break

Submission status: Accepted

Solution code:
dict = [771,16843009,15,131841,387,33153,1539]
while True:
    cell = reduce(lambda x,y:x+y,map(lambda x:int(raw_input(),2)<<(8*x),xrange(8)))
    for i in [cell >> j for j in xrange(255)]:
        try:
            print chr(dict.index(i) + ord('A'))
        except ValueError:
            continue
    try:
        raw_input()
    except:
        break

Submission status: Accepted

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def judge(height, indexes):
    if height == 1:
        return 'C'
    if height == 4:
        return 'B'
    idx0, idx1 = indexes
    if height == 2:
        return 'EAG'[1+idx0-idx1]
    if height == 3:
        return 'FD'[idx0-idx1]

while True:
    it = (stdin.readline() for _ in xrange(8))
    L = [line for line in it if line.count('1')]
    indexes = (L[i].index('1') for i in xrange(2))
    print(judge(len(L), indexes))
    if not stdin.readline():
        break

Submission status: Accepted

Solution code:

import sys


class Plain:
    def __init__(self, mat):
        self.plain = mat

    def show(self):
        for i in range(8):
            print self.plain[i]

    def shift(self):
        while all_zero(self.plain[0]):
             shift_lis(self.plain)
        while all_zero(map(lambda x: x[0], self.plain)):
            map(shift_lis, self.plain)
        return self

    def match_figure(self, figs):
        for (name, fig) in figs:
            if self.match(fig):
                return  name

    def match(self, fig):
        lx = len(fig[0])
        ly = len(fig)
        result = True
        for y in range(ly):
            for x in range(lx):
                if not fig[y][x] == self.plain[y][x]:
                    result = False
        return result


def all_zero(lis):
    return sum(lis) == 0 

def shift_lis(lis):
    a = lis.pop(0)
    lis.append(a)
    return lis

A = [[1,1],[1,1]]
B = [[1],[1],[1],[1]]
C = [[1,1,1,1]]
D = [[0,1],[1,1],[1,0]]
E = [[1,1,0],[0,1,1]]
F = [[1,0],[1,1],[0,1]]
G = [[0,1,1],[1,1,0]]

figures = zip("ABCDEFG", [A,B,C,D,E,F,G])

while True:
    try:
        p = []
        for i in range(8):
            p.append(map(int, list(raw_input())))
        plain = Plain(p)
        plain.shift()
        print plain.match_figure(figures)
        raw_input()
    except:
        exit()

Submission status: Accepted

Solution code:
while True:
    L=[]
    for i in range(8):
        s=raw_input()
        if "1" in s:
            L.append("0"+s+"0")
    if len(L)==4:
        print "B"
    elif len(L)==3:
        x=L[0].index("1")
        print "F" if L[1][x+1]=="1" else "D"
    elif len(L)==2:
        x=L[0].index("1")
        if L[1][x+1]=="1":
            print "A" if L[1][x]=="1" else "E"
        else:
            print "G"
    else:
        print "C"
    try:
        skip=raw_input()
    except EOFError:
        break

Submission status: Accepted

Solution code:
import re
while True:
    try:
        s = ''.join([raw_input() for s in range(8)])
        print '    C    GAE    D F      B'[len(re.findall('1.*1', s)[0])]
        raw_input()
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys;import re
for s in sys.stdin.read().split('\n\n'):print '    C    GAE    D F      B'[len(re.findall('1.*1', s.replace('\n',''))[0])]

Submission status: Accepted

Solution code:
import sys;import re
for s in sys.stdin.read().split('\n\n'):print 'CBD FGAE'[(len(re.findall('1.*1', s.replace('\n',''))[0])-4)%10]

Submission status: Accepted

Solution code:
import sys;import re
for s in sys.stdin.read().split('\n\n'):print 'CBD FGAE'[(len(re.findall('1.*1',s.replace('\n',''))[0])-4)%10]

Submission status: Accepted

Solution code:
N = 8
ptn=[[(0,0),(0,1),(1,0),(1,1)], [(0,0),(1,0),(2,0),(3,0)],
    [(0,0),(0,1),(0,2),(0,3)], [(0,1),(1,0),(1,1),(2,0)],
    [(0,0),(0,1),(1,1),(1,2)], [(0,0),(1,0),(1,1),(2,1)],
    [(0,1),(0,2),(1,0),(1,1)]]

def readdata():
    x = ""
    while x=="":
        try: x=raw_input()
        except: return []
    x=[x]    
    for i in range(N-1):
        x.append(raw_input())
    return x

def f0036(x):
    try: return "ABCDEFG"[ptn.index(x)]
    except: return False

while True:
    dt = readdata()
    if dt==[]: break

    xx=[]
    yy=[]
    for y in range(N):
        e = dt[y]
        try: x = e.index("1")
        except: continue
        while x < N:
            if e[x]=="1":
                xx.append(x)
                yy.append(y)
            x = x+1
    p = zip([e-min(yy) for e in yy], [e-min(xx) for e in xx])
    print f0036(p)

Submission status: Accepted

Solution code:
N = 8
def readdata():
    x = ""
    while x=="":
        try: x = raw_input()
        except: return []
    for i in range(N-1):
        x += raw_input()
    return x

def f0036(x):
    ptn = [18, 48, 6, 30, 20, 34, 16]
    try: return "ABCDEFG"[ptn.index(sum(x)-x[0]*4)]
    except: return False

while True:
    dt = readdata()
    if dt==[]: break
    dt = [i for i,c in enumerate(dt) if c=="1"]
    print f0036(dt)

Submission status: Accepted

Solution code:
N = 8
def readdata():
    x = ""
    while x=="":
        try: x = raw_input()
        except: return []
    for i in range(N-1):
        x += raw_input()
    return x

while True:
    dt = readdata()
    if dt==[]: break
    dt = [i for i,c in enumerate(dt) if c=="1"]
    ptn = [18, 48, 6, 30, 20, 34, 16]
    try: print "ABCDEFG"[ptn.index(sum(dt)-dt[0]*4)]
    except: break