-
-
Save anon5r/314206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_cell(): | |
cell =[] | |
for line in open('p.txt', 'r'): | |
line = list(line.rstrip()) | |
cell.append(line) | |
return cell | |
def chaise(cell, x, y): | |
if cell[x][y] == 'c': | |
return False | |
pre = cell[x][y] | |
cell[x][y] = 'c' | |
point = 1 | |
if(x != 0): | |
if pre == cell[x-1][y]: | |
point += chaise(cell, x-1, y) | |
if(y != 0): | |
if pre == cell[x][y-1]: | |
point += chaise(cell, x, y-1) | |
if(x != len(cell[0])-1): | |
if pre == cell[x+1][y]: | |
point += chaise(cell, x+1, y) | |
if(y != len(cell)-1): | |
if pre == cell[x][y+1]: | |
point += chaise(cell, x, y+1) | |
return point | |
def calc_result(): | |
cell = create_cell() | |
result = [[0, 0, 0]] | |
for x in range(0, len(cell)): | |
for y in range(0, len(cell[0])): | |
p = chaise(cell, x, y) | |
if p >= result[0][2]: | |
if(result[0] != p): | |
result = [] | |
result.append([x, y, p]) | |
return result | |
def print_count(result): | |
cell = create_cell() | |
for i in range(0, len(result)): | |
chaise(cell, result[i][0], result[i][1]) | |
for i in range(0, len(cell)): | |
count = 0 | |
for j in range(0, len(cell[i])): | |
if cell[i][j] == 'c': | |
count+=1 | |
print count | |
result = calc_result() | |
print_count(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment