Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
def rotate(mat):
  mat2 = []
  for i in range(len(mat[0])):
    s = ""
    for k in range(len(mat)):
      s = s + mat[k][i]
    mat2.append(s)
  return mat2

H,W=map(int, input().split())
mat = []
for i in range(H):
  a = input()
  if "#" in a:
    mat.append(a)

for count in range(H+W):
  for i in range(len(mat)-1, 0, -1):
    if not "#" in mat[i]:
      del mat[i]
  rotate(mat)
  for i in range(len(mat)-1, 0, -1):
    if not "#" in mat[i]:
      del mat[i]
  rotate(mat)
  
for i in range(len(mat)):
  print(mat[i])

def strCut(s,n):
  return s[0:n] + s[n+1:len(s)]

H,W=map(int, input().split())
s_list = []
for i in range(H):
  s = input()
  if "#" in s: s_list.append(s)

    


H,W=map(int, input().split())
masu_list = []
for i in range(H):
  S=str(input())
  if S.count('#') != 0:
    masu_list.append(S)

yet = True
while yet:
  for i in range(len(masu_list[0])):
    if masu_list[i].count('#') == 0:
      masu_list.delete(i,1)

def oneCol(mat,n):
  ans = ""
  for i in range(len(mat)):
    ans = ans + mat[i][n]
  return ans

def strCut(s,n):
  return s[0:n] + s[n+1:len(s)]

def lowCut(mat):
  for i in range(len(mat)):
    if not "#" in mat[len(mat)-i-1]:
      delete mat[len(mat)-i-1]
  return mat

def colCut(mat):
  for i in range(len(mat[0])):
    if not "#" in oneCol(mat,len(mat[0])-i-1):
      mat2 = []
      for k in range(len(mat)):
        mat2.append(strCut(mat[k],len(mat[0])-i-1))
  return mat
      

H,W=map(int, input().split())
s_list = []
for i in range(H):
  s = input()
  if "#" in s: s_list.append(s)

    
while True:
  lowCut(mat)
  colCut(mat)
  print(mat)

def rotate(mat):
  mat2 = []
  for i in range(len(mat[0])):
    s = ""
    for k in range(len(mat)):
      s = s + mat[k][i]
    mat2.append(s)
  return mat2

H,W=map(int, input().split())
mat = []
for i in range(H):
  a = input()
  if "#" in a:
    mat.append(a)

for count in range(H+W):
  for i in range(len(mat)-1, 0, -1):
    if not "#" in mat[i]:
      del mat[i]
  rotate(mat)
  for i in range(len(mat)-1, 0, -1):
    if not "#" in mat[i]:
      del mat[i]
  rotate(mat)
  

print(mat)

def rotate(mat):
  mat2 = []
  for i in range(len(mat[0])):
    s = ""
    for k in range(len(mat)):
      s = s + mat[k][i]
    mat2.append(s)
  return mat2

H,W=map(int, input().split())
mat = []
for i in range(H):
  a = input()
  if "#" in a:
    mat.append(a)

for count in range(H+W):
  for i in range(len(mat)-1, -1, -1):
    if not "#" in mat[i]:
      del mat[i]
  mat = rotate(mat)
  for i in range(len(mat)-1, -1, -1):
    if not "#" in mat[i]:
      del mat[i]
  mat = rotate(mat)
  
for i in range(len(mat)):
  print(mat[i])


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted