Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - # 08. Bombs
 - #
 - # Multidimensional Lists - Exercise 1
 - # https://judge.softuni.org/Contests/Practice/Index/1835#7
 - ===================================================================
 - Input:1
 - 4
 - 8 3 2 5
 - 6 4 7 9
 - 9 9 3 6
 - 6 8 1 2
 - 1,2 2,1 2,0
 - Output:1
 - Alive cells: 3
 - Sum: 12
 - 8 -4 -5 -2
 - -3 -3 0 2
 - 0 0 -4 -1
 - -3 -1 -1 2
 - ===================================================================
 - Input:2
 - 3
 - 7 8 4
 - 3 1 5
 - 6 4 9
 - 0,2 1,0 2,2
 - Output:2
 - Alive cells: 3
 - Sum: 8
 - 4 1 0
 - 0 -3 -8
 - 3 -8 0
 - ===================================================================
 - # 08. Bombs
 - def is_inside(current_row, current_col): # It's square matrix => rows = cols
 - return 0 <= current_row < SIZE and 0 <= current_col < SIZE
 - surroundings = [(0, 1), (0, -1), (-1, 0), (1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1)]
 - SIZE = int(input())
 - matrix = []
 - for _ in range(SIZE):
 - matrix.append([int(x) for x in input().split()])
 - bombs = input().split()
 - if matrix:
 - for current_bomb in bombs:
 - b_row, b_col = eval(current_bomb)
 - damage = matrix[b_row][b_col]
 - if damage <= 0:
 - continue
 - matrix[b_row][b_col] = 0
 - for direction in surroundings:
 - row, col = b_row + direction[0], b_col + direction[1]
 - if is_inside(row, col) and matrix[row][col] > 0:
 - matrix[row][col] -= damage
 - total_sum = 0
 - alive_cells = 0
 - for sub_matrix in matrix:
 - for num in sub_matrix:
 - if num > 0:
 - total_sum += num
 - alive_cells += 1
 - print(f'Alive cells: {alive_cells}')
 - print(f'Sum: {total_sum}')
 - for sub_matrix in matrix:
 - print(*sub_matrix)
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment