Skip to content

Instantly share code, notes, and snippets.

@mavyfaby
Last active February 15, 2022 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavyfaby/d9b54c7cb29cc7833e8b1336c6580a85 to your computer and use it in GitHub Desktop.
Save mavyfaby/d9b54c7cb29cc7833e8b1336c6580a85 to your computer and use it in GitHub Desktop.
Bombs and $100 bills code in Python by Mavy💖
import sys
def main(lines):
new_lines = lines[1:]
output_lines = list()
# First line workaround
first_line = lines[0].split()
n = int(first_line[0])
m = int(first_line[1])
k = int(first_line[2])
# Converting new lines to mutable lines
for line in new_lines:
lst = list()
for letter in line:
lst.append(letter)
output_lines.append(lst)
# Getting the locations of bombs
tmp_locations = list()
bomb_locations = list()
for lst in output_lines:
indexes = list()
i = 0
for letter in lst:
if letter == 'B':
indexes.append(i)
i = i + 1
tmp_locations.append(indexes)
y = 0
for location in tmp_locations:
for x in location:
pos = list()
pos.append(x)
pos.append(y)
bomb_locations.append(tuple(pos))
y = y + 1
# Coding the bomb
for bx, by in bomb_locations:
output_lines[by][bx] = 0
for ys in range(n):
for xs in range(m):
if xs == bx or ys == by:
output_lines[ys][xs] = 0
# Converting remained numbers into int
y = 0
for line in output_lines:
x = 0
for n in line:
output_lines[y][x] = int(n)
x = x + 1
y = y + 1
# FINAL step: adding remained numbers
total = 0
for line in output_lines:
for num in line:
total = total + num
# Print the result
print(total)
if __name__ == '__main__':
lines = []
for l in sys.stdin:
lines.append(l.rstrip('\r\n'))
main(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment