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:
H,W = map(int,input().split())
L = []


for _ in range(H):
    s=input()
    l=[]
    for x in s:
        l.append(x)
    for x in l:
        if x == ".":
            pass
        else:
            L.append(l)
            break
delete=[]
cou=0
for i in range(W):
    cnt = 0
    for j in range(len(L)):
        if L[j][i]  == '.':
            cnt += 1
        else:
            cnt = 0
    if cnt == len(L):
        delete.append(i-cou)
        cou+=1
for i in delete:
    for j in range(len(L)):
        del L[j][i]

for x in L:
    for y in x:
        print(y,end="")
    print()

Submission status: Accepted

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

white = [0]*W
board = []
for _ in [0]*H:
    line = input().rstrip()
    for i in range(W):
        if line[i] == '.': white[i] += 1
    if '#' in line:
        board.append(list(line))

for line in board:
    for i in range(W):
        if white[i] == H: continue
        else: print(line[i], end='')
    print()

Submission status: Accepted

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

a = [list(input()) for i in range(H)]
b = ['.']*W

while b in a:
    a.remove(b)

for j in range(W):
    flag = 0
    for i in a:
        if i[j] == '#':
            flag = 1
            break
    if flag == 0:
        for i in a:
            i[j] = ''
    
for i in a:
    print(''.join(i))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
s = [input() for _ in range(H)]
h = []
w = []
for i in range(H):
    if '#' not in s[i]:
        h.append(i)

for i in range(W):
    ok = True
    for j in range(H):
        if s[j][i] == "#":
            ok = False
    if ok: w.append(i)
for i in range(H):
    if i in h: continue
    for j in range(W):
        if j not in w:
            print(s[i][j],end="")
    print()

Submission status: Accepted

Solution code:
def main():
    h, w = map(int, input().split())
    board = []

    cddt = []
    omission_line = 0
    for i in range(h):
        line = input()
        if line == "." * w:
            omission_line += 1
        else:
            cells = list(line)
            for n, c in enumerate(cells):
                if c == ".":
                    cddt.append(n)
            board.append(cells)

    for line in board:
        for i, c in enumerate(line):
            if (cddt.count(i) + omission_line) != h:
                print(c, end="")
        print("")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(h):
    A = list(input())
    if  '#' in A:
        ans.append(A)
        
count = [0] * w
for i in range(len(ans)):
    for j in range(w):
        if ans[i][j] == '.':
            count[j] += 1

num = len(ans)
for i in range(num):
    for j in range(w - 1, -1, -1):
        if count[j] == num:
            del ans[i][j]
        
for i in range(len(ans)):
    print(''.join(ans[i]))

Submission status: Accepted

Solution code:
import numpy as np

h, w = [int(x) for x in input().split()]
board = [input() for i in range(h)]
dellist = []
for i in range(h):
    if '#' not in board[i]:
        dellist.append(i)
for i in sorted(dellist, reverse=True):
    del board[i]

board = [list(x) for x in board]
board_t = np.array(board).T.tolist()
dellist2 = []
for i in range(w):
    if '#' not in board_t[i]:
        dellist2.append(i)
for i in sorted(dellist2, reverse=True):
    del board_t[i]

board_t_t = np.array(board_t).T

[print(''.join(x)) for x in board_t_t]

Submission status: Accepted

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

for i in range(H):
    a[i] = list(map(str, 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):
    i = input()
    if "#" in i:
        a.append(i)

ans = []
for i in zip(*a):
    if "#" in i:
        ans.append(i)
for j in zip(*ans):
    print(*j,sep = "")

Submission status: Accepted

Solution code:
import numpy as np
h,w=list(map(int,input().split()))
n=[list(input())for i in range(h)]
s=np.array(n)
s=s.T
s=s.tolist()
s=[t for t in s if t!=["."]*h]
k=len(s)
p=np.array(s)
p=p.T
p=p.tolist()
p=[t for t in p if t!=["."]*k]
for i in range(len(p)):
    h=p[i]
    d=len(h)
    c=""
    for j in range(d):
        c+=h[j]
    print(c)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for _ in range(H):
    i = list(input())
    if '#' in i:
        a.append(i)
ans = zip(*[i for i in zip(*a) if '#' in i])
for s in ans:
    print(*s, sep='')
#copy code

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [input() for _ in range(H)]
A = list(filter(lambda a: any(x == "#" for x in a), A))
A = list(filter(lambda a: any(x == "#" for x in a), zip(*A)))

for a in zip(*A):
    print("".join(a))

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:
import numpy as np

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

B = A[:, np.any(A == '#', axis = 0)]
C = B[np.any(B == '#', axis = 1), :]

for i in range(C.shape[0]):
    print(''.join(C[i]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
hmax = H
board = []
for _ in range(H):
	line = list(input().rstrip())
	if '#' in line:
		board.append(line)
	else: hmax -= 1

cnt = [0] * W
for line in board:
	for w, px in enumerate(line):
		if px == '.': cnt[w] += 1

for line in board:
	for w, px in enumerate(line):
		if cnt[w] == hmax: continue
		else: print(px, end='')
	print()

Submission status: Accepted

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

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

ans_H = []
for i in range(H):
    if "#" in LL[i]:
        ans_H.append(i)

ans_W = []
for i in range(W):
    cnt = 0
    for j in range(H):
        if LL[j][i] == "#":
            cnt = 1
    if cnt == 1:
        ans_W.append(i)


for i in ans_H:
    for j in ans_W:
        print(LL[i][j], end = "")
    print()

Submission status: Accepted

Solution code:
# coding: utf-8
h, w = map(int, input().split())
a = [input() for _ in range(h)]

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 i in range(h):
    A.append(list(input()))
#行に対しての作業
ans = 0
'''
for i in A:
    print(A.index)
    if(i.count('.') == w):
        del A[A.index(i)]   
'''
B = []
for i in range(h):
    if(A[i].count('.') != w):
        B.append(A[i])


count=0
ans=0
for i in range(w):
    i -=ans
    for j in B:
        if(j[i] == '.'):
            count+=1
    if(count==len(B)):
        for j in B:
            del j[i]
        ans +=1
    count=0

for i in B:
    for j in i:
        print(j, end="")
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = list()
for i in range(H):
	A.append(input())
for i in range(H):
	okrow = False
	for k in range(W):
		if A[i][k] == '#':
			okrow = True
	if okrow:
		for j in range(W):
			okcol = False
			for k in range(H):
				if A[k][j] == '#':
					okcol = True
			if okcol:
				print(A[i][j], end = '')
		print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = list()
for i in range(h):
    s = input()
    if s != '.'*w:
        a.append(s)
n = len(a)
k = 0
while k < w:
    if all(a[i][k] == '.' for i in range(n)):
        for j in range(n):
            a[j] = a[j][:k] + a[j][k+1:]
        w -= 1
    else:
        k += 1
for i in range(n):
    print(a[i])

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [0] * H
for _ in range(H):
    A[_] = input()
l = []
l2 = []
count = 0

for i in range(W):
    for j in range(H):
        if A[j][i] == '.':
            count += 1
    if count == H:
        l.append(i)
    count = 0
l.sort(reverse = True)
for k in range(H):
    for m in l:
        A[k] = A[k][:m] + A[k][m + 1:]
# print(A)
# for l in range(H):
#     if A[l] == '.' * len(A[l]):
#         l2.append(l)
# for _ in l2:
#     A.pop(_)
B = [i for i in A if i != '.'*len(A[0])]
# print(B)
for _ in range(len(B)):
    print(B[_])

Submission status: Accepted

Solution code:
def str_del(string,index):
    string = string[:index]+string[index+1:]
    return string




H,W=map(int,input().split())
lines=[]
for i in range(H):
    get=input()
    flag=True
    for s in get:
        if s=='#':
            flag=False
            break
    if not flag:
        lines.append(get)
    else:
        H-=1


i=0
while(i<W):
    same_flag = True

    for s in range(len(lines)):
        #print(lines)
        if(lines[s][i]=='#'):
                same_flag=False
                break


    if same_flag:
        for s in range(len(lines)):
            lines[s]=str_del(lines[s],i)

        i-=1
        W-=1
            #print(lines[s])
        #print('deleted')

    i+=1


for i in range(len(lines)):
    print(lines[i])

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
skiph = []
skipw = []
for i in range(H):
    if a[i].count('.') == len(a[i]):
        skiph.append(i)
for i in range(W):
    if a[0][i] == '.':
        for j in range(H):
            if a[j][i] == '#':
                break
        else:
            skipw.append(i)
for i in range(H):
    if i in skiph:
        continue
    for j in range(W):
        if j in skipw:
            continue
        print(a[i][j], end="")
    else:
        print()

Submission status: Accepted

Solution code:
import numpy as np

a1, a2 = map(int, input().split())
mx = [[list(i) for i in input().split()] for i in range(a1)]
mx = np.reshape(mx,-1)
mx = [0 if i == '.' else 1 for i in mx]
mx = np.reshape(mx,[a1,a2])

w = min(np.append(sum(mx,1),sum(mx,0)))

while w == 0:
    mx = mx[np.sum(mx,1) > 0]
    mx = mx.T[np.sum(mx.T,1) > 0].T
    w = min(np.append(sum(mx,1),sum(mx,0)))

res = np.where(mx == 0 ,".","#")

for x in res:
    print(''.join(x))

Submission status: Accepted

Solution code:
H, W = list(map(int, input().split()))
a = []
h = []
w = []
aa = ''

for i in range(H):
    a_ = input()
    aa += a_
    a.append(a_)
    if '#' in a_:
        h.append(i)

for i in range(W):
    if '#' in aa[i::W]:
        w.append(i)
        
for i in range(H):
    if i not in h:
        continue
    flag = False
    for l in range(W):
        if l in w:
            print(a[i][l], end='')
            flag = True
    if flag == True:
        print('')

Submission status: Accepted

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

a1 = []
for h in range(H):
  if not all(s=="." for s in a[h]):
    a1.append(a[h])

a2 = [[] for i in range(len(a1))]
for w in range(W):
  tmp_a = [row[w] for row in a1]
  if not all(s=="." for s in tmp_a):
    for i in range(len(tmp_a)):
      a2[i].append(tmp_a[i])

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

Submission status: Accepted

Solution code:
t = input().split(" ")
H = int(t[0])
W = int(t[1])
list1 = []
for i in range(H):
    t = str(input())
    list1.append(t)
erase_index = []
for i in range(H):
    W_count = 0
    for j in range(W):
        if list1[i][j] == '.':
            W_count += 1
    if W_count == W:
        erase_index.append(i)
erase_char = []
for i in range(W):
    H_count = 0
    for j in range(H):
        if list1[j][i] == '.':
            H_count += 1
    if H_count == H:
        erase_char.append(i)
for i in range(len(erase_index)):
    list1.pop(erase_index[len(erase_index)-1-i])
ans = []
for i in zip(*list1):
    ans.append(list(i))
for i in range(len(erase_char)):
    ans.pop(erase_char[len(erase_char)-1-i])
answer = []
for i in zip(*ans):
    answer.append(list(i))
for i in range(len(answer)):
    s = ""
    for j in range(len(answer[i])):
        s += str(answer[i][j])
    print(s)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for _ in range(H):
    i = list(input())
    if '#' in i:
        a.append(i)
ans = zip(*[i for i in zip(*a) if '#' in i])
for s in ans:
    print(*s, sep='')

Submission status: Accepted

Solution code:
coord = []


def compress_y():
    global coord
    for y in range(len(coord)):
        if all(c == '.' for c in coord[y]):
            coord = coord[:y] + coord[y + 1:]
            return True
    return False


def compress_x():
    global coord
    for x in range(0, len(coord[0])):
        if all(row[x] == '.' for row in coord):
            for y in range(len(coord)):
                coord[y] = coord[y][:x] + coord[y][x + 1:]
            return True
    return False


def main():
    global coord
    h, w = map(int, input().split())
    coord = [list(input()) for _ in range(h)]
    while compress_y():
        pass
    while compress_x():
        pass

    for row in coord:
        print(''.join(row))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

row = []
column = []

for i in range(H):
    flag = True
    for j in range(W):
        if a[i][j] != '.':
            flag = False
            break
    if flag:
        row.append(i)

for j in range(W):
    flag = True
    for i in range(H):
        if a[i][j] != '.':
            flag = False
            break
    if flag:
        column.append(j)

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

Submission status: Accepted

Solution code:
a,b = map(int,input().split(" "))
ar = []
br = [[] for i in range(b)]
for i in range(a):
    l = list(input())
    if "#" in l:
        ar.append(l)
    for j in range(b):
        br[j].append(l[j])
cr = []
for i,r in enumerate(br):
    if "#" not in r:
        cr.append(i)
er = [[] for i in range(len(ar))]
for i in range(len(ar)):
    for j in range(b):
        if j not in cr:
            er[i].append(ar[i][j])
for r in er:
    print("".join(r))

Submission status: Accepted

Solution code:
height, width = (int(x) for x in input().split())
matrix = []

for i in range(height):
  matrix.append(input())

row = [0] * width
column = [0] * height

for i in range(height):
  if '#' in matrix[i]:
    column[i] = 1
    for j in range(width):
      if (matrix[i][j] == '#'):
        row[j] = 1

for i in range(height):
  if (column[i] == 1):
    for j in range(width):
      if (row[j] == 1):
        print(matrix[i][j], end = '')
    print()

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())

field = [list(input()) for x in range(h)]
for i, row in list(enumerate(field))[::-1]:
    if "#" not in row:
        del field[i]

field = list(np.transpose(field))
for i, row in list(enumerate(field))[::-1]:
    if "#" not in row:
        del field[i]

for i in np.transpose(field):
    print("".join(i))

Submission status: Accepted

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

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

for i in reversed(range(len(a))):
  if '#' not in a[i]:
    del a[i]

a = list(zip(*a))
for i in reversed(range(len(a))):
  if '#' not in a[i]:
    del a[i]

a = list(zip(*a))
         
for i in a:
  print(''.join(i))

Submission status: Accepted

Solution code:
import numpy as np
H, W = list(map(int, input().split()))

a = np.array([list(input()) for i in range(H)])

at = np.all(a == '.', axis = 1)
for i in reversed(range(len(at))):
  if at[i]:
    a = np.delete(a, i, 0)

at = np.all(a == '.', axis = 0)
for i in reversed(range(len(at))):
  if at[i]:
    a = np.delete(a, i, 1)
for i in a:
  print(''.join(i))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = []
for _ in range(H):
    a = list(input())
    if '#' in a:
        A.append(a)
    else:
        H -= 1

for i in range(W-1,-1,-1):
    ch = 0
    for j in range(H):
        if A[j][i] == '#':
            ch = 0
            break
        else:
            ch = 1
    if ch == 1:
        for k in range(H):
            del A[k][i]
    
for a in A:
    print(''.join(a))

Submission status: Accepted

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

for i in range(H):
    list = [i for i in input()]
    if list.count("#") > 0:
        HWlist.append(list)
    for j in range(W):
        if list[j] == "#":
            w.append(j)
    
for i in range(len(HWlist[0])-1,-1,-1):
    if i not in w:
        for j in HWlist:
            del j[i]

for i in range(len(HWlist)):
    print("".join(HWlist[i]))

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int,input().split())
x=[]
for n in range(N):
	x.append(list(input()))

for __ in range(2):
	check=[]
	count=0
	for _ in range(len(x[0])):
		check.append(".")
	for xi in x:
		if xi == check:
			count+=1
	for _ in range(count):
		x.remove(check)
	x=np.array(x).T.tolist()

for i in range(len(x)):
	for j in range(len(x[0])):
		print(x[i][j],end="")
	if i != len(x)-1:
		print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
hlist = []
wlist = []
a = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            hlist.append(i)
            wlist.append(j)
for i in set(hlist):
    for j in set(wlist):
        print(a[i][j], end ="")
    print()

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
p = [input() for _ in range(h)]
p = [row for row in p if not all(map(lambda i: i == ".", row))]
p = [col for col in zip(*p) if not all(map(lambda i: i == ".", col))]
for row in zip(*p):
    print("".join(row))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
t = []
for _ in range(H):
    x = input()
    if x != '.' * W:
        t += [x]
num = len(t)
k = []
for s in zip(*t):
    s = ''.join(s)
    if s != '.' * num:
        k += [s]
for x in zip(*k):
    print(''.join(x))

Submission status: Accepted

Solution code:
H, W = map(int, raw_input().split())
a = []
for i in range(H):
  a.append(raw_input())
b = [r for r in a if "#" in r]
c = ["".join(r) for r in zip(*b) if "#" in r]
for l in zip(*c):
  print "".join(l)

Submission status: Accepted

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

grid = []
for i in range(h):
    row = str(input())

    for j in range(w):
        if row[j] == "#":
            grid.append(row)
            break

cls = []
for i in range(w):
    count = 0

    for j in range(len(grid)):    

        if grid[j][i] == "." :
            count += 1

    if count >= len(grid) :
        cls.append(i)

for i in range(len(grid)):
    for j in range(w) :
        if j not in cls:
            print(grid[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()

tate = [False]*h
yoko = [False]*w

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            tate[i] = True
            yoko[j] = True

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

Submission status: Accepted

Solution code:
import numpy as np

h,w=input().split()
h=int(h)
w=int(w)

list1 =[input() for i in range(h)]
#print(list1)

list2=[]
for i in range(h):
  if list1[i].count('#') > 0:
    list2.append(list1[i])
#print(list2)
list2_num=len(list2)

list4=[]
for i in range(list2_num):
  list3=(list(list2[i]))
  list4.append(list3)
#print(list4)
list4=np.array(list4).T
#print(list4)

list4=list4.tolist()
list5=[]
for i in range(w):
  if list4[i].count('#') > 0:
    list5.append(list4[i])
#print(list5)

list5=np.array(list5).T
#print(list5)
list5=list5.tolist()
#print(list5)
for i in range(len(list5)):
  for j in range(len(list5[0])):
    print(list5[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:
f=lambda s:zip(*[t for t in s if'#'in t]);
for r in f(f(__import__('sys').stdin)):print(*r,sep='')

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
d = []
for i in range(h):
    d.append(input())
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if d[i][j] == '#':
            row[i] = True
            col[j] = True
for i in range(h):
    if row[i]:
        s = ""
        for j in range(w):
            if col[j]:
                s += d[i][j]
        if len(s) > 0:
            print(s)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
M=[0]*H
for i in range(H):
    M[i]=input()
H_cnt=[0]*H
W_cnt=[0]*W
for i in range(H):
    for j in range(W):
        if M[i][j]=='#':
            H_cnt[i]=1
            W_cnt[j]=1
for i in range(H):
    for j in range(W):
        if W_cnt[j]==1 and H_cnt[i]==1:
            print(M[i][j],end='')
    if H_cnt[i]==1:
        print()

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
#print(a)
c=[list(input()) for i in range(a)]
#print(c[0])
d=['.'for i in range(b)]
#print(d)
e=[]
for i in range(a):
	if c[i]!=d:
		e.append(c[i])
#print(e)
#for k in range(len(e)):
f=[]
for i in zip(*e):
	f.append(list(i))
#print(f)

g=['.'for i in range(len(e))]
#print(g)
h=[]
for i in range(len(f)):
	if f[i]!=g:
		h.append(f[i])
#print(h)
j=[]
for i in zip(*h):
	j.append(list(i))
for i in range(len(j)):
	print(''.join(j[i]))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = []
for i in range(h):
    if a[i] != '.'*w:
        b.append(a[i])
ans = []
for i in range(w):
    flag = False
    for j in range(len(b)):
        flag |= b[j][i]=='#'
    if not flag:
        ans.append(i)
for i in b:
    for j,k in enumerate(i):
        if j not in ans:
            print(k,end='')
    print('')

Submission status: Accepted

Solution code:
# 値の取得
H, W = map(int, input().split())
# 配列の準備
A = []
# #がある列のみをAについか
for i in range(H):
    a = list(input())  # 一文字ずつに分割されたリストなる
    if '#' in a:
        A.append(a)
    else:
        H = H - 1
# .のみの行を削除
for i in range(W - 1, -1, -1):  # rangeはiの値をfor文中でいじっても変更不可
    ch = 0
    for j in range(H):
        if A[j][i] == '#':
            ch = 0
            break
        else:
            ch = 1
    if ch == 1:
        for k in range(H):
            del A[k][i]
# 出力
for i, a in enumerate(A):
    print(''.join(a))

Submission status: Accepted

Solution code:
import numpy as np
WH='.'
BK='#'
x=input()
x=x.split()
H=int(x[0])
W=int(x[1])
a=[[] for i in range(H)]
num=[]
numnum=0
for i in range(H):
    x=input()
    for j in range(W):
        a[i].append(x[j])
for i in range(H):
    flag=0
    for j in range(W):
        if a[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==W:
        num.append(i)
        numnum=numnum+1
for i in range(numnum):
    a.pop(num[i]-i)
H=H-numnum
a_n=np.array(a)
tr=a_n.T
a=tr.tolist()
num=[]
numnum=0
num_num=0
for i in range(W):
    flag=0
    for j in range(H):
        if a[i][j]==WH:
            flag=flag+1
        else:
            flag=flag-1
    if flag==H:
        num.append(i)
        numnum=numnum+1
        flag=0
    else:
        flag=0
for i in range(numnum):
    a.pop(num[i]-i)
W=W-numnum
a_n=np.array(a)
a=a_n.T
for i in range(H):
    ans=''
    for j in range(W):
        ans=ans+a[i][j]
    print(ans)

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 i in range(H):
    a = list(input())
    if "#" in a:
        A.append(a)
    else:
        H -= 1
for j in range(W-1,-1,-1):
    for i in range(H):
        if A[i][j] == "#":
            break
        elif i == H - 1:
            for k in range(H):
                del A[k][j]
for e in A:
    print("".join(e))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
L = [input() for i in range(H)]
X = [False for i in range(W)]
Y = [False for i in range(H)]

for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" :
            X[x] = True
            Y[y] = True

for y in range(H) :
    if Y[y] == True :
        ANS = []
        for x in range(W) :
            if X[x] == True :
                ANS.append(L[y][x])
        print("".join(ANS))

Submission status: Accepted

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

row = []
column = []

for i in range(h):
    flag = 1
    first = "."
    for j in range(w):
        if a[i][j] != first:
            flag = 0
    if flag == 0:
        row.append(i)

for j in range(w):
    flag = 1
    first = "."
    for i in range(h):
        if a[i][j] != first:
            flag = 0
    if flag == 0:
        column.append(j)


for i in row:
    output = ""
    for j in column:
        output += a[i][j]
    if output != "":
        print(output)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h,w = li()
grid = [lc() for _ in range(h)]
new_h = []
new_w = []

for hi in range(h):
    if "#" in grid[hi]:
        new_h.append(hi)

for wj in range(w):
    for hi in range(h):    
        if "#" in grid[hi][wj]:
            new_w.append(wj)
            break
        
ans = [["" for _ in range(len(new_w))] for _ in range(len(new_h))]

for i,nhi in enumerate(new_h):
    for j,nwj in enumerate(new_w):
        ans[i][j] = grid[nhi][nwj]
        
for row in ans:
    print("".join(row))

Submission status: Accepted

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

del_r = []
for i in range(H):
    if all([c=='.' for c in src[i]]):
        del_r.append(i)

del_c = []
for i,col in enumerate(zip(*src)):
    if all([c=='.' for c in col]):
        del_c.append(i)

for i in range(H):
    if i in del_r: continue
    ans = ''
    for j in range(W):
        if j in del_c: continue
        ans += src[i][j]
    print(ans)

Submission status: Accepted

Solution code:
l = [int(i) for i in input().split()]
H = l[0]
W = l[1]

my_map = []
for i in range(H) :
	s = input()
	if (s.find('#') != -1) :
		my_map.append(list(s))

remove_col_indexes = []
for col_index in range(len(my_map[0])) :
	arr = []
	for row_index in range(len(my_map)) :
		arr.append(my_map[row_index][col_index])

	if len([s for s in arr if '#' in s]) == 0 :
		remove_col_indexes.append(col_index)

result_map = []
for row_index in range(len(my_map)) :
	row_arr = []
	for col_index in range(len(my_map[row_index])) :
		if (col_index not in remove_col_indexes) :
				row_arr.append(my_map[row_index][col_index])
	
	result_map.append(row_arr)

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
lst = []
for _ in range(H):
    s = input()
    if s.find('#') >= 0:
        lst.append(s)

lst2 = []
for tpl in zip(*lst):
    if '#' in tpl:
        lst2.append(tpl)

for tpl in zip(*lst2):
    print(''.join(tpl))