-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBomberman.py
68 lines (49 loc) · 1.36 KB
/
Bomberman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'bomberMan' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts following parameters:
# 1. INTEGER n
# 2. STRING_ARRAY grid
#
def bomberMan(n, grid):
# Write your code here
if n==1:
return grid
if n%2==0:
return['O'*c for i in range(r)]
n//=2
for q in range((n+1)%2+1):
newgrid = [['O']*c for i in range(r)]
def set(x,y):
if 0<=x<r and 0<=y<c:
newgrid[x][y] = '.'
xi = [0,0,0,1,-1]
yi = [0,-1,1,0,0]
for x in range(r):
for y in range(c):
if grid[x][y]== 'O':
for i,j in zip(xi, yi):
set(x+i, y+j)
grid = newgrid
return["".join(x) for x in grid]
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
r = int(first_multiple_input[0])
c = int(first_multiple_input[1])
n = int(first_multiple_input[2])
grid = []
for _ in range(r):
grid_item = input()
grid.append(grid_item)
result = bomberMan(n, grid)
fptr.write('\n'.join(result))
fptr.write('\n')
fptr.close()