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):
h, w = map(int, input().split())
a = []
for i in range(h):
    A = list(map(str,input().split()))
    a.append(A)
kesu = []
for i in range(h):
    b = str(a[i])
    ten = 0
    for l in range(w):
        if b[l+2] == ",":
           ten += 1
    if w == ten :
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    a.pop(K-i)
hi = []
for i in range(w):
    hkari = ""
    for l in range(len(a)):
        h = str(a[l])
        hz = str(h[i+2])
        hkari += str(hz)
    hi.append(hkari)
kesu = []
for i in range(len(hi)):
    b = str(hi[i])
    ten = 0
    for l in range(len(b)):
        if b[l] == ",":
            ten += 1
    if len(b) == ten:
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    hi.pop(K-i)
b = len(str(hi[0]))
ans = []
for i in range(b):
    hkari = ""
    for l in range(len(hi)):
        h = str(hi[l])
        hz = str(h[i])
        hkari += str(hz)
    ans.append(hkari)
for i  in range(len(ans)):
    print(ans[i])


h, w = map(int, input().split())
a = []
for i in range(h):
    A = list(map(str,input().split()))
    a.append(A)
kesu = []
for i in range(h):
    b = str(a[i])
    ten = 0
    for l in range(w):
        if b[l+2] == ",":
           ten += 1
    if w == ten :
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    a.pop(K-i)
hi = []
for i in range(w):
    hkari = ""
    for l in range(len(a)):
        h = str(a[l])
        hz = str(h[i+2])
        hkari += str(hz)
    hi.append(hkari)
kesu = []
for i in range(len(hi)):
    b = str(hi[i])
    ten = 0
    for l in range(len(b)):
        if b[l] == ",":
            ten += 1
    if len(b) == ten:
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    hi.pop(K-i)
b = len(str(hi[0]))
ans = []
for i in range(b):
    hkari = ""
    for l in range(len(hi)):
        h = str(hi[l])
        hz = str(h[i])
        hkari += str(hz)
    ans.append(hkari)
print(ans)

h, w = map(int, input().split())
a = []
for i in range(h):
    A = list(map(str,input().split()))
    a.append(A)
kesu = []
for i in range(h):
    b = str(a[i])
    ten = 0
    for l in range(w):
        if b[l+2] == ".":
           ten += 1
    if w == ten :
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    a.pop(K-i)
hi = []
for i in range(w):
    hkari = ""
    for l in range(len(a)):
        h = str(a[l])
        hz = str(h[i+2])
        hkari += str(hz)
    hi.append(hkari)
kesu = []
for i in range(len(hi)):
    b = str(hi[i])
    ten = 0
    for l in range(len(b)):
        if b[l] == ".":
            ten += 1
    if len(b) == ten:
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    hi.pop(K-i)
b = len(str(hi[0]))
ans = []
for i in range(b):
    hkari = ""
    for l in range(len(hi)):
        h = str(hi[l])
        hz = str(h[i])
        hkari += str(hz)
    ans.append(hkari)
for i  in range(len(ans)):
    print(ans[i])

Verdicts: Wrong Answer

Wrong Answer

Accepted