/
ne-ilyxa
/
AP1_Py_T01
Обзор
Документация
Войти
/
ne-ilyxa
/
AP1_Py_T01
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/exercise3.py
51 строка
1 KB
git1worker
Finished
16 авг 2025, 14:22
16 авг 2025, 14:22
e5a8f98
Код
Авторство
О чём код?
with open("input.txt", "r") as in_file: lines = in_file.readlines() matrix = list() for i in range(len(lines)): if lines[i] != '\n': matrix.append(lines[i].split()) def isSquare(matrix, i, j): cnt_x = cnt_y = 1 i_cp = i j_cp = j while i_cp < len(matrix) and matrix[i_cp][j] != "0": cnt_y += 1 i_cp += 1 while j_cp < len(matrix[0]) and matrix[i][j_cp] != "0": cnt_x += 1 j_cp += 1 return cnt_x == cnt_y def delAdjacentRecursively(matrix_, i, j): matrix_[i][j] = "0" # r d l u if j + 1 < len(matrix_[0]) and matrix_[i][j + 1] == "1": delAdjacentRecursively(matrix_, i, j + 1) if i + 1 < len(matrix_) and matrix_[i + 1][j] == "1": delAdjacentRecursively(matrix_, i + 1, j) if j - 1 >= 0 and matrix_[i][j - 1] == "1": delAdjacentRecursively(matrix_, i, j - 1) if i - 1 >= 0 and matrix_[i - 1][j] == "1": delAdjacentRecursively(matrix_, i - 1, j) squares = 0 circles = 0 for i in range(len(matrix[0])): for j in range(len(matrix)): if matrix[i][j] == "1": if isSquare(matrix, i, j): squares += 1 else: circles += 1 delAdjacentRecursively(matrix, i, j) print(squares, circles)