Problem:


Score : 200 points

Problem Statement

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.

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

There is at least one black square in the whole grid.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

Sample Input 1

4 4
##.#
....
##.#
.#.#

Sample Output 1

###
###
.##

The second row and the third column in the original grid will be removed.

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

As there is no row or column that consists only of white squares, no operation will be performed.

Sample Input 3

4 5
.....
.....
..#..
.....

Sample Output 3

#

Sample Input 4

7 6
......
....#.
.#....
..#...
..#...
......
.#..#.

Sample Output 4

..#
#..
.#.
.#.
#.#



Sample input:
4 4
##.#
....
##.#
.#.#


Sample output:
###
###
.##

Submission status: Accepted

Solution code:
import numpy as np

H,W = list(map(int, input().split()))

mat = np.zeros((H, W))
original_mat = []

removed_line = []
removed_column = []

for i in range(H):
    row = input()
    line = []
    for j, c in enumerate(row):
        if c == "#":
            mat[i, j] = 1

    # print(mat[i,:])
    if np.sum(mat[i,:]) == 0:
        removed_line.append(i)
    else:
        original_mat.append(row)

for i in range(W):
    # print(mat[:,i])
    if np.sum(mat[:,i]) == 0:
        removed_column.append(i)

# print(removed_line)
# print(removed_column)

for row in original_mat:
    for i, c in enumerate(row):
        if i not in removed_column:
            print(c, end="")
    print("\n", end="")

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
ans = []

for _ in range(H):
    line = list(str(input()))
    if '#' not in line:
        continue
    else:
        ans.append(line)

ans = np.array(ans).T.tolist()
hoge = []
for i in range(len(ans)):
    line = ans[i]
    if '#' not in line:
        continue
    else:
        hoge.append(line)

ans = np.array(hoge).T.tolist()

for a in ans:
    print("".join(a))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [[i for i in input()] for _ in range(h)]
b = [x for x in a if "#" in x]
c = zip(*[x for x in zip(*b) if "#"in x])
for d in c:
    print("".join(d))

Submission status: Accepted

Solution code:
def slove():
    import sys
    import bisect
    import collections
    import fractions
    import heapq
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    a = [list(str(input().rstrip('\n'))) for _ in range(h)]
    hl = [True] * h
    wl = [True] * w
    for i in range(h):
        if a[i].count("#") == 0:
            hl[i] = False
    for i in range(w):
        b = False
        for j in range(h):
            if a[j][i] == "#":
                b = True
                break
        if not b:
            wl[i] = False
    for i in range(h):
        if hl[i]:
            l = []
            for j in range(w):
                if wl[j]:
                    l.append(a[i][j])
            print("".join(l))


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())

grid = []
for i in range(H):
    s = input()
    if s != "." * W:
        grid.append(list(s))

H = len(grid)

for i in reversed(range(W)):
    if all(grid[j][i] == "." for j in range(H)):
        for k in range(H):
            grid[k].pop(i)

print("\n".join("".join(r) for r in grid))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())

a = []
for i in range(H):
    a.append(input())

#print(a)

row_list = []
col_list = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row_list.append(i)
            col_list.append(j)

for i in range(H):
    ans = ""
    for j in range(W):
        if (i in row_list) and (j in col_list):
            ans += a[i][j]
    if(len(ans) > 0):
        print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    H, W = map(int, input().split())
    a = list()
    for i in range(H):
        a.append(input())
    
    # 黒がある場所のリスト化
    col_list = list()
    row_list = list()

    for i in range(H):
        for j in range(W):
            if a[i][j] == '#':
                if (i in row_list) is False:
                    row_list.append(i)
                if (j in col_list) is False:
                    col_list.append(j)
    
    for i in range(H):
        ans = ''
        for j in range(W):
            if (j in col_list) and (i in row_list):
                ans += a[i][j]
        if len(ans) > 0:
            print(ans)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
H_cnt = 0
maze = ["" for _ in range(W)]
maze_ok = [True]*W
for _ in range(H):
  m = input()
  if m != "."*W:
    for i in range(W):
      maze[i] += m[i]
  else:
    H_cnt += 1
for i in range(W):
  if maze[i]=="."*(H-H_cnt):
    maze_ok[i]=False

ans = ["" for _ in range(H-H_cnt)]
for i in range(H-H_cnt):
  for j in range(W):
    if maze_ok[j]:
      ans[i] += maze[j][i]

for a in ans:
  print(a)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
delcol = {i: True for i in range(w)}
for _ in range(h):
    _a = input()
    if _a == "."*w:
        continue

    for _w in range(w):
        delcol[_w] &= ("." == _a[_w])

    a.append(_a)

for _a in a:
    for _w in range(w):
        if not delcol[_w]:
            print(_a[_w], end="")

    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]

yoko = [False] * H
for i in range(H) :
    k = set()
    for j in range(W) :
        k.add(a[i][j])
    if len(k) == 1 and '.' in k :
        yoko[i] = True
        
tate = [False] * W
for i in range(W) :
    k = set()
    for j in range(H) :
        k.add(a[j][i])
    if len(k) == 1 :
        tate[i] = True
        
for i in range(H) :
    if yoko[i] : 
        continue
    s = ''
    for j in range(W) :
        if tate[j] and '.' in k :
            continue
        s += a[i][j]
    print(s)

Submission status: Accepted

Solution code:
import numpy as np

h, w = map(int, input().split())
A = np.array([list(input()) for i in range(h)])

ans = []
for i in range(h):
    a = ''
    for j in range(w):
        if '#' in A[i] and '#' in A[:, j]:
            a += A[i][j]
    if a != '':
        ans.append(a)

for a in ans:
    print(a, sep='')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
h = [0]*H
w = [0]*W
l = [list(input()) for i in range(H)]
for i in range(H):
    if all([i=='.' for i in l[i][:]]):
        h[i]=1
lt = list(zip(*l))
for j in range(W):
    if all([j=='.' for j in lt[j][:]]):
        w[j]=1
for i in range(H):
    for j in range(W):
        if h[i]==0 and w[j]==0:
            print(l[i][j],end='')
    if h[i]==0:
        print()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  h, w = na()
  a = [ns() for _ in range(h)]
  a = ["".join(hw) for hw in zip(*a) if hw.count("#") > 0]
  a = ["".join(hw) for hw in zip(*a) if hw.count("#") > 0]
  print("\n".join(a))

main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(map(str,input())) for _ in range(h)]
cnt = h
for i in range(h):
    if '#' not in a[i]:
        a[i].clear()
        cnt -= 1
if cnt != h:
    a = [_ for _ in a if _]
i = 0
while i < w:
    for j in range(cnt):
        if a[j][i] == '#':
            break
    else:
        for j in range(cnt):
            a[j].pop(i)
        w -= 1
        i -= 1
    i += 1
for i in range(cnt):
    print(''.join(map(str,a[i])))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())

x=[input() for _ in range(h)]
y=[x[i] for i in range(h) if '#'in x[i]]
      
c=[]
for i in range(len(y)):
      for j in range(w):
            if y[i][j]=='#':
                  c.append(j)
d=list(set(c))
z=[]
for i in range(len(y)):
      w=[]
      for j in d:
            w.append(y[i][j])
      z.append(w)

for i in range(len(z)):
      print(''.join(z[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())

li = []
for i in range(h):
    str = list(input())  # 1文字区切りでリスト格納
    li.append(str)

flg = True


# 縦に見ていく
for i in range(w):
    flg2 = True
    for j in range(h):
        if li[j][i] == "#":
            flg2 = False
            break
    
    if flg2:
        for j in range(h):
            li[j][i] = "a"

for i in range(h):
    flg2 = True
    for j in range(w):
        if li[i][j] == "#":
            flg2 = False
            break
    if flg2:
        for j in range(w):
            li[i][j] = "a"

    
for i in range(h):
    flg3 = False
    for j in range(w):
        if li[i][j] != "a":
            print(li[i][j], end ="")
            flg3=True
    
    if flg3:
        print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split(' '))
a = [list(str(input())) for _ in range(h)]
checker = []
for i in range(len(a)):
    if all(x == '.' for x in a[i]):
        checker.append(i)
    else:
        continue
for i in range(1, len(checker)+1):
    a.pop(checker[-i])
checker = []
for i in range(len(a[0])):
    if all(a[j][i] == '.' for j in range(len(a))):
        checker.append(i)
    else:
        continue
for i in range(1, len(checker)+1):
    for j in range(len(a)):
        a[j].pop(checker[-i])


for i in a:
    print(''.join(i))

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]

a = [a[idx] for idx in range(len(a)) if a[idx].count(".") < len(a[idx])]
a = np.array(a).T.tolist()
a = [a[idx] for idx in range(len(a)) if a[idx].count(".") < len(a[idx])]
a = np.array(a).T.tolist()

for row in range(len(a)):
    print("".join(a[row]))

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]

def del_blank_row(a):
    del_flg = []
    for row in range(len(a)):
        if a[row].count(".") == len(a[row]):
            del_flg.append(1)
        else:
            del_flg.append(0)
    a = [a[idx] for idx in range(len(a)) if del_flg[idx] == 0]
    return a

a = del_blank_row(a)
a = np.array(a).T.tolist()
a = del_blank_row(a)
a = np.array(a).T.tolist()

for row in range(len(a)):
    print("".join(a[row]))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
A = [""]*H
row = [False]*H #行
col = [False]*W #列
for i in range(H):
    A[i] = input()
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            row[i] = True
            col[j] = True

for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(A[i][j], end="")
        print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []

for _ in range(H):
    row = list(input())
    if "#" in row:
        A.append(row)

for i in range(W):
    if "#" not in [a[i] for a in A]:
        for a in A:
            a[i] = None

for a in A:
    for i in range(W):
        s = a[i]
        if s != None:
            print(s, end="")
    print()

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
A = np.array([list(input()) for _ in range(H)])

row = [False] * H
column = [False] * W

for h in range(H):
    for w in range(W):
        if A[h, w] == "#":
            break
        if w == W-1:
            row[h] = True

for w in range(W):
    for h in range(H):
        if A[h, w] == "#":
            break
        if h == H-1:
            column[w] = True

for r, is_deleted in reversed(list(enumerate(row))):
    if is_deleted:
        A = np.delete(A, r, 0)

for c, is_deleted in reversed(list(enumerate(column))):
    if is_deleted:
        A = np.delete(A, c, 1)

for row in A:
    print("".join(row))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
matrix = []
ans = []
for i in range(H):
    h = list(input())
    if "#" in h:
        matrix.append(h)
for j in range(W):
    w = [w_[j] for w_ in matrix]
    if "#" in w:
        ans.append(w)
for k in range(len(ans[0])):
    print("".join([r[k] for r in ans]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
matrix = []
hd = []
wd = []

for i in range(H):
    h = list(input())
    matrix.append(h)
    if h == ["."] * W:
        continue
    hd.append(i)

for i in range(W):
    w = [list(w_[i]) for w_ in matrix]
    if w == [["."]] * H:
        continue
    wd.append(i)

ansmatrix = []
row = []
for i in hd:
    for j in wd:
        row.append(matrix[i][j])
    ansmatrix.append(row)
    row = []

for ansrow in ansmatrix:
    print("".join(ansrow))

Submission status: Accepted

Solution code:
def main():
    H,W = map(int, input().split())
    grid = []
    for i in range(H):
        input_line = str(input())
        if '#' in input_line:
            grid.append(input_line)
    

    for j in range(W):
        del_flg = True
        for line in grid:
            if(line[j] == '#'):
                del_flg = False
                break
        if(del_flg):
            for i,line in enumerate(grid):
                line = line[:j] + '0' + line[j+1:]
                grid[i] = line
    
    for line in grid:
            print(line.replace('0',''))
    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
 
H, W=map(int, input().split())
matrix=np.zeros((H, W))
 
for i in range(H):
  s=input()
  for j in range(W):
    if s[j]=='#':
      matrix[i, j]=1
      
for i in range(H):
  if np.sum(matrix[i, :]==0)==W:
    matrix[i, :]=-1
    
for i in range(W):
  if np.sum(matrix[:, i]<=0)==H:
    matrix[:, i]=-1
    
i=0
for i in range(H):
  if np.sum(matrix[i, :]==-1)==W:
    pass
  else:
    for j in range(W):
      if matrix[i, j]==0:
        print('.', end='')
      elif matrix[i, j]==1:
        print('#', end='')
      else:
        pass
    print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
src = [input() for _ in range(h)]
li = []
for i,z in enumerate(src[0]):
    if z == '.':
        li.append(i)
eliminate_column_index = []
for l in li:
    tmp = True
    for s in src:
        if s[l] == '#':
            tmp = False
            break
    if tmp == True:
        eliminate_column_index.append(l)
eliminate_row_index = []
for si,sr in enumerate(src):
    if sr == '.'*w:
        eliminate_row_index.append(si)
for s_row,ss in enumerate(src):
    if s_row in eliminate_row_index:
        continue
    tmp = ''
    for i,s in enumerate(ss):
        if i not in eliminate_column_index:
            tmp += s
    if tmp != '':
        print(tmp)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    A = [list(input()[:-1]) for _ in range(H)]

    B = [False]*H
    C = [False]*W
    for i in range(H):
        for j in range(W):
            if A[i][j]=="#":
                B[i] = True
                C[j] = True
    
    ans = ""
    for i in range(H):
        if B[i]==False:
            continue
        for j in range(W):
            if C[j]==False:
                continue
            ans += A[i][j]
        ans += "\n"

    print(ans[:-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    A = [list(input()[:-1]) for _ in range(H)]

    B = [0]*H
    C = [0]*W
    for i in range(H):
        for j in range(W):
            if A[i][j]==".":
                B[i] += 1
                C[j] += 1
    
    ans = ""
    for i in range(H):
        if B[i]==W:
            continue
        for j in range(W):
            if C[j]==H:
                continue
            ans += A[i][j]
        ans += "\n"

    print(ans[:-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
b = [x for x in a if '#' in x]
c = zip(*[y for y in zip(*b) if '#' in y])
for d in c:
    print(''.join(d))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
li,li2 = [],[]
for i in range(h):
    a = list(input())
    if "#" in a:
        li.append(a)
for i in range(len(li)):
    for j in range(w):
        if li[i][j] == ".":
            li[i][j] = 0
        elif li[i][j] == "#":
            li[i][j] = 1

li = list(zip(*li))
for i in range(len(li)):
    if 1 in li[i]:
        li2.append(li[i])
li2 = list(zip(*li2))
for i in range(len(li2)):
    li2[i] = list(li2[i])
for i in range(len(li2)):
    for j in range(len(li2[i])):
        if li2[i][j] == 0:
            li2[i][j] = "."
        elif li2[i][j] == 1:
            li2[i][j] = "#"
for i in range(len(li2)):
    print("".join(li2[i]))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [[j for j in input()]for i in range(h)]
b = [x for x in a if '#' in x]
c = zip(*[y for y in zip(*b) if '#' in y])
for d in c:
  print(''.join(d))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
b = [x for x in a if "#" in x]
c = zip(*[y for y in zip(*b) if "#" in y])
for d in c:
  print("".join(d))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input())for _ in range(h)]
b=[]
for i in range(h):
    if a[i].count('.')==w:
        continue
    else:
        b.append(a[i])
c=[]
for i in range(w):
    d=[]
    for j in range(len(b)):
        d.append(b[j][i])
    c.append(d)
e=[]
for i in range(w):
    if c[i].count('.')==len(b):
        continue
    else:
        e.append(c[i])
for i in range(len(b)):
    for j in range(len(e)):
        print(e[j][i],end='')
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]

cntH = 0
for i in range(H-1, -1, -1):
    flag = True
    for j in range(W):
        if a[i][j] == '#':
            flag = False
            break
    if flag:
        a.pop(i)
        cntH+=1

for j in range(W-1, -1, -1):
    flag = True
    for i in range(H-cntH):
        if a[i][j] == '#':
            flag = False
    if(flag):
        for i in range(H-cntH):
            a[i].pop(j)

for i in range(H-cntH):
    for j in range(len(a[i])):
        print(a[i][j], end='')
    print('')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for i in range(h)]

flagh = [0]*h
flagw = [0]*w

for i in range(0,h):
    if a[i]=="."*w:
        flagh[i] = 1
    for j in range(0,w):
        if a[i][j] == ".":
            flagw[j] += 1

for i in range(h):
    if flagh[i] != 1:
        for j in range(w):
            if flagw[j] != h:
                print(a[i][j],end="")
        print("")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=list(list(input()) for _ in range(h))
for i in range(h):
    for j in range(w):
        if a[i][j]=='.': a[i][j]=0
        elif a[i][j]=='#': a[i][j]=1
for i in range(h):
    if sum(a[i])==0: a[i]=[]
a=[x for x in a if x]
h=len(a)
b=[row for row in zip(*a)]
for i in range(w):
    if sum(b[i])==0: b[i]=[]
b=[x for x in b if x]
w=len(b)
a=[list(row) for row in zip(*b)]
for i in range(h):
    for j in range(w):
        if a[i][j]==0: a[i][j]='.'
        elif a[i][j]==1: a[i][j]='#'
for row in a: print(''.join(row))

Submission status: Accepted

Solution code:
h,w = (int(i) for i in input().split())
a = [input() for _ in range(h)]

tate, yoko = [], []
for i in range(h):
  if any([s == '#' for s in a[i]]):
    tate.append(i)
for i in range(w):
  if any(a[j][i] == '#' for j in range(h)):
    yoko.append(i)

for i in tate:
  for j in yoko:
    print(a[i][j], end='')
  print('')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
row_list = []
[row_list.append(input()) for h in range(H)]

col_list = []
for w in range(W):
    col = ''
    for h in range(H):
        col += row_list[h][w]
    col_list.append(col)


romit_index_list = [rindex for rindex, r in enumerate(row_list) if r == '.' * W]
comit_index_list = [cindex for cindex, c in enumerate(col_list) if c == '.' * H]

matrix = ''
for h in range(H):
    if h in romit_index_list:
        pass
    else:
        for w in range(W):
            if w in comit_index_list:
                pass
            else:
                matrix += row_list[h][w]


result = [matrix[n: n + W - len(comit_index_list)]
          for n in range(0, len(matrix), W - len(comit_index_list))]


ans = '\n'.join(result)
print(ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
L = [input() for _ in range(a)]
L1 = []
L3 = []
for i in range(a):
  if not L[i] == "."*b:
    L1.append(L[i])
L2 = list(map(list, zip(*L1)))
for k in range(len(L2)):
  if not "".join(L2[k]) == "."*len(L2[k]):
    L3.append("".join(L2[k]))
L4 = list(map(list, zip(*L3)))
for v in range(len(L4)):
  print("".join(L4[v]))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    table = [[i == "#" for i in input().strip()] for _ in range(h)]
    table = list(filter(lambda x: sum(x), table))
    table = [[row[i] for row in table] for i in range(w)]
    table = list(filter(lambda x: sum(x), table))
    table = [[row[i] for row in table] for i in range(len(table[0]))]
    for row in table:
        print("".join(["#" if v else "." for v in row]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())

a = []

for y in range(h):
    a.append([_ for _ in input()])

rem_x = []
rem_y = []

for y in range(h):
    fl = 0
    for x in range(w):
        if a[y][x] == '#':
            fl = 1
    if fl == 1:
        rem_y.append(y)

for x in range(w):
    fl = 0
    for y in range(h):
        if a[y][x] == '#':
            fl = 1
    if fl == 1:
        rem_x.append(x)

for y in rem_y:
    for x in rem_x:
        print(a[y][x],end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
b=[]
c=[]
#a = [x for x in a if "#" in x]
for x in a:
    if "#" in x:
        b.append(x)
#print(b)
bT = list(zip(*b))
#print(bT)
for x in bT:
    if "#" in x:
        c.append(x)
#print(c)
cT = list(zip(*c))
for i in cT:
    print("".join(i))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = [list(input()) for _ in range(H)]
while ["." for _ in range(W)] in a:
    a.remove(["." for _ in range(W)])
c = []
for l in range(len(a[0])):
    s = 0
    for i in range(len(a)):
        if a[i][l] == ".":
            s += 1
    if s == len(a):
        c.append(l)
for i in range(len(a)):
    t = 0
    for l in c:
        del a[i][l-t]
        t += 1
for i in range(len(a)):
    print("".join(a[i]))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[]
for h in range(H):
    A.append(list(map(str,input().split())))
A = [a for a in A if "#" in a[0]]
del_l=[]
for w in range(W):
    s="".join([a[0][w] for a in A])
    if "#" not in s:
        del_l.append(w)
for a in A:
    for w in range(W):
        if w not in del_l:
            print(a[0][w],end="")
    print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
Data = []

for _ in range(H):
    Data.append(input())

hdata = set()
wdata = set()

for h in range(H):
    for w in range(W):
        if Data[h][w] == '#':
            hdata.add(h)
            wdata.add(w)

for h in range(H):
    output = False
    for w in range(W):
        if h in hdata and w in wdata:
            print(Data[h][w],end='')
            output = True
    if output:
        print('')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
Data1 = []

tbl = str.maketrans({'.':'0','#':'1'})
for _ in range(H):
    s = input().translate(tbl)
    s = list(map(int,list(s)))
    if sum(s) > 0:
        Data1.append(s)

dellist = []
for w in range(W):
    flag = False
    for data in Data1:
        if data[w] == 1:
            flag = True
            break
    if flag == False:
        dellist.append(w)

for i in range(len(dellist)-1,-1,-1):
    for data in Data1:
        data.pop(dellist[i])

for data in Data1:
    for i in range(len(data)):
        if data[i] == 0:
            print('.',end='')
        else:
            print('#',end='')
    print("")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
m = [list(input()) for _ in range(h)]
mr = [r for r in m if '#' in r]
mrc = [c for c in zip(*mr) if '#' in c]
print(*(''.join(row) for row in zip(*mrc)), sep='\n')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
m = [list(input()) for _ in range(h)]

row_idx = []
for idx, row in enumerate(m):
    if not row.count('#'):
        row_idx.append(idx)

col_idx = []
for idx, col in enumerate(zip(*m)):
    if not col.count('#'):
        col_idx.append(idx)

for i, row in enumerate(m):
    if i in row_idx:
        continue
    else:
        for idx in col_idx[::-1]:
            row.pop(idx)
        print(*row, sep='')

Submission status: Accepted

Solution code:
H,W = map(int, input().split())

a = [list(input()) for _ in range(H)]

i = 0
while i < H:
    for j in range(W):
        if a[i][j] != '.':
            break
    else:
        a.pop(i)
        H -= 1
        continue
    i += 1

i = 0
while i < W:
    for j in range(H):
        if a[j][i] != '.':
            break
    else:
        for k in range(H):
            a[k].pop(i)
        W -= 1
        continue
    i += 1

for i in range(H):
    for j in range(W):
        print(a[i][j], end='')
    print()

Submission status: Accepted

Solution code:
h,w=input().split()
a=[list(input()) for i in range(int(h))]
for i in zip(*[i for i in zip(*[i for i in a if '#' in i]) if '#' in i]):
    print(''.join(i))

Submission status: Accepted

Solution code:
h,w=input().split()
a=[list(input()) for i in range(int(h))]

l1=[i for i in a if '#' in i]
l2=[i for i in zip(*l1) if '#' in i]
for i in zip(*l2):
    print(''.join(i))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]

l1=[]
for i in a:
    if '#' in i:
        l1.append(i)
l2=[]
for i in zip(*l1):
    if '#' in i:
        l2.append(i)
l3=zip(*l2)
for i in l3:
    print(''.join(i))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
for i in range(h):
    if '#' not in a[i]:
        a[i]=['n']*w
for i in range(w):
    l=[a[j][i] for j in range(len(a))]
    if '#' not in l:
        for k in range(len(a)):
           a[k][i]='n'
for i in a:
    l=[x for x in i if x!='n']
    if l:
        print(''.join(l))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
row = [False]*h
line = [False]*w
a = []
for i in range(h):
    A = input()
    a.append(A)

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            row[i] = True
            line[j] = True

for i in range(h):
    if row[i]:
        for j in range(w):
            if line[j]:
                print(a[i][j], end = "")
        print()

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [list(x for x in input()) for _ in range(h)]
b = []
c = []
for i in range(h):
  if '#' in a[i]:
    continue
  else:
    b.append(i)

for j in range(w):
  for k in range(h):
    if '#' == a[k][j]:
      break
    elif k == h-1:
      c.append(j)

for m in range(h):
  count = 0
  if m in b:
    continue
  for n in range(w):
    if n in c:
      continue
    else:
      count +=1
      print(a[m][n], end='')
    if count == (w-len(c)):
      print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())

ls = [list(input()) for i in range(h)]
ls1 = [i for i in ls if '#' in i]
ls2 = [i for i in zip(*ls1) if '#' in i]
ls3 = [i for i in zip(*ls2)]

for i in ls3:
    print(''.join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = [list(input()) for i in range(h)]
A1 = [a for a in A if "#" in a]
A2 = [a for a in zip(*A1) if "#" in a]
A3 = [a for a in zip(*A2)]
for a in A3:
  print("".join(a))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
lst = []
for i in range(H):
    lst.append(list(input()))
for i in range(H-1, -1, -1):
    if '#' not in lst[i]:
        del lst[i]
for j in range(W-1, -1, -1):
    cnt = 0
    for i in range(len(lst)):
        if lst[i][j] == '#':
            cnt += 1
    if cnt == 0:
        for i in range(len(lst)):
            del lst[i][j]
for i in lst:
    print(''.join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
aList = []
for i in range(h):
    a = input()
    if a.count(".") != w:
        aList.append(a)
h = len(aList)

aLen = w

for j in range(w):
    aSum = sum(aList[i][w - j - 1] == "." for i in range(h))
    if aSum == h:
        for a in range(h):
            aList[a] = aList[a][0:w - j - 1] + aList[a][w - j:aLen]
        aLen -= 1


for i in range(h):
    print(aList[i])

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a=["" for _ in range(h)]
for i in range(h):
    a[i]=list(input())
for i in range(h):
    key=0
    for j in range(w):
        if a[i][j]=="#":
            key=1
    if key==0:
        for j in range(w):
            a[i][j]=""
for i in range(w):
    key=0
    for j in range(h):
        if a[j][i]=="#":
            key=1
    if key==0:
        for j in range(h):
            a[j][i]=""
for i in range(h):
    if a[i]!=["" for _ in range(w)]:
        print(''.join(a[i]))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [list(input().strip()) for _ in range(H)]

for i in range(H-1,-1,-1):
    ind = 0
    for j in range(W):
        if A[i][j]!=".":
            ind = 1
            break
    if ind==0:
        A.pop(i)
for j in range(len(A[0])-1,-1,-1):
    ind = 0
    for i in range(len(A)):
        if A[i][j]!=".":
            ind = 1
            break
    if ind==0:
        for i in range(len(A)):
            A[i].pop(j)
for i in range(len(A)):
    x = ""
    for j in range(len(A[i])):
        x += str(A[i][j])
    print(x)