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 math
import copy
import sys

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
inputList = []
inputNumList = []
for i in range(a):
    inputNum = input()
    inputNumList = list(inputNum)
    inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

# row
for i in range(len(inputList)-1, -1, -1):
    flg = True
    for j in range(len(inputList[i])):
        if inputList[i][j] =="#":
            flg = False
            break

    if flg:
        del inputList[i]

# colum
for j in range(b-1, -1, -1):
    flg = True
    for i in range(len(inputList)):
        if inputList[i][j] == "#":
            flg = False
            break

    if flg:
        for i in range(len(inputList)):
            del inputList[i][j]

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

Submission status: Accepted

Solution code:
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())
grid = [list(input()) for _ in range(h)]

rows = [0] * h
for i in range(h):
    for j in range(w):
        rows[i] |= (grid[i][j] == '#')

cols = [0] * w
for j in range(w):
    for i in range(h):
        cols[j] |= (grid[i][j] == '#')

for i in range(h):
    if not rows[i]:
        continue
    for j in range(w):
        if not cols[j]:
            continue
        print(grid[i][j], end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [input() for i 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 = [int(x) for x in input().split()]
a = [j for j in [input() for i in range(h)] if '#' in j]
a = [i for i in zip(*a) if '#' in i]
print('\n'.join(["".join(line) for line in zip(*a)]))

Submission status: Accepted

Solution code:
H,W = list(map(int,input().split()))
import numpy as np
A = np.zeros([H,W])
ans = np.zeros([H,W]).astype(np.unicode)
for i in range(H):
    ans[i,:] = [x for x in input()]
    A[i,:] = [1 if x=='#' else 0 for x in ans[i,:]]

rw = np.all(A == 0, axis = 1)
cl = np.all(A == 0, axis = 0)

ans = ans[~rw,:]
ans = ans[:,~cl]
for i in range(ans.shape[0]):
    print("".join(ans[i,:]))

Submission status: Accepted

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

for y in range(h):
    a = input()
    grid.append(a)
    remove = True
    for x in range(w):
        if a[x] == "#":
            remove = False
            if x not in stay_x:
                stay_x.append(x)        
    if remove != True:
        stay_y.append(y)
stay_x.sort()
for y in stay_y:
    out = ""
    for x in stay_x:
        out += grid[y][x]
    print(out)

Submission status: Accepted

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

ans1 = []
for a in A:
    if sum(a) != 0:
        ans1.append(a)

ans2 = []
for a in zip(*ans1):
    if sum(a) != 0:
        ans2.append(a)

ans2 = [list(map(str, i)) for i in zip(*ans2)]
for a in ans2:
    print(''.join(a).replace('0', '.').replace('1', '#'))

Submission status: Accepted

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



grid = list(filter(lambda r: any([i=='#' for i in r]), grid))
grid = zip(*grid)
grid = list(filter(lambda r: any([i=='#' for i in r]), grid))
grid = zip(*grid)
for i in grid:
    print(''.join(i))

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 sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(H, W, inputs):
    delete_row = []
    i = 0
    while len(inputs) != 0 and i < len(inputs):
        is_all_white = True
        for c in inputs[i]:
            is_all_white = is_all_white and c == '.'
        if is_all_white:
            inputs.pop(i)
        else:
            i += 1
    blank_columns = {i for i in range(len(inputs[0]))}
    for row in inputs:
        for i, c in enumerate(row):
            if c != '.' and i in blank_columns:
                blank_columns.remove(i)
    for row in inputs:
        for i, c in enumerate(row):
            if i not in blank_columns:
                print(c, end='')
        print('')

    # return inputs


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [H, W] = string_to_int(input())
    ret = solve(H, W, inputs(H))
    # print(ret)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for i in range(h)]
cnt = 0
b = []
for i in a:
  if i.count('.') != w:
    b.append(i)
  else:
    cnt += 1
if len(b) == 1:
    print(b[0].replace('.',''))
else:
    b = list(map(list,b))
    transpose = []
    c = []
    d = []
    for i in range(len(b[0])):
        tmp = []
        for v in b:
            tmp.append(v[i])
        transpose.append(tmp)
    for i in transpose:
        c.append(''.join(i))
    for i in c:
        if i.count('.') != h-cnt:
            d.append(i)
    d = list(map(list,d))
    transpose = []
    c = []
    for i in range(len(d[0])):
        tmp = []
        for v in d:
            tmp.append(v[i])
        transpose.append(tmp)
    for i in transpose:
        print(''.join(i))

Submission status: Accepted

Solution code:
import numpy
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
a = numpy.asarray(a)
a = a[:, numpy.any(a == "#", axis=0)]
a = a[numpy.any(a == "#", axis=1)]
for i in range(len(a)):
    print("".join(a[i]))

Submission status: Accepted

Solution code:
h,w = list(map(int,input().split()))
a = [[i for i in input()] for _ in range(h)]
remove = []
for r in range(h):
  flag = True
  for c in range(w):
    if a[r][c] == "#":
      flag = False
      break
  if flag:
    remove.append(r)
for i in range(len(remove)):
  a.pop(remove[i])
  remove = [j-1 for j in remove]
remove = []
for c in range(w):
  flag = True
  for r in range(len(a)):
    if a[r][c] == "#":
      flag = False
      break
  if flag:
    remove.append(c)
for c in range(len(remove)):
  for r in range(len(a)):
    a[r].pop(remove[c])
  remove = [i-1 for i in remove]
  
for r in range(len(a)):
  print("".join(a[r]))

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 = []
tmp = []
ttt = []
ans = []
annn = []
for i in range(H):
    aa = input()
    aa = list(aa)
    a.append(aa)
for i in range(H):
    for j in range(W):
        if '#' == a[i][j]:
            tmp.append(a[i])
            break
H = len(tmp)
for i in range(W):
    t = []
    for j in range(H):
        t.append(tmp[j][i])
    ttt.append(t)
for i in range(W):
    for j in range(H):
        if '#' == ttt[i][j]:
            ans.append(ttt[i])
            break
W = len(ans)
for i in range(H):
    t = []
    for j in range(W):
        t.append(ans[j][i])
    annn.append(t)
for i in range(H):
    print(''.join(annn[i]))

Submission status: Accepted

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

for i in range(H):
	flg=True
	for j in range(W):
		if aHW[i][j]=='#':
			flg=False
			break
	if flg:
		ignoreH.append(i)

for i in range(W):
	flg=True
	for j in range(H):
		if aHW[j][i]=='#':
			flg=False
			break
	if flg:
		ignoreW.append(i)


for i in range(H):
	if i in ignoreH:
		continue
	for j in range(W):
		if j in ignoreW:
			continue
		print(aHW[i][j],end="")
	print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
sl = [input() for _ in [0]*h]
l = []
for i in range(len(sl)):
  if sl[i].count('#') > 0:
    l.append(i)
sl = [sl[i] for i in l]
l = []
for j in range(len(sl[0])):
  flag = False
  for i in range(len(sl)):
    if sl[i][j] == '#':
      flag = True
  if flag == True:
    l.append(j)
for s in sl:
  s = [s[j] for j in l]
  print(''.join(s))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
for i in range(h):
    ai = input()
    if ai.count("#") >0:
        a.append(ai)

b = []
for i in range(w):
    b.append([])
    for j in range(len(a)):
            b[i].append(a[j][i])

c = []
for i in range(len(b)):
    if b[i].count("#")>0:
        c.append(b[i])

ans = []
for i in range(len(c[0])):
    ans.append([])
    for j in range(len(c)):
        ans[i].append(c[j][i])

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	h, w = map(int, input().strip().split())
	a = [[] for _ in range(h)]
	for i in range(h):
		a[i] = list(input().strip())
	for i in range(h):
		flag = True
		for j in range(w):
			if a[i][j] == '#':
				flag = False
				break
		if flag:
			a[i] = [-1] * w
	for j in range(w):
		flag = True
		for i in range(h):
			if a[i][j] == '#':
				flag = False
				break
		if flag:
			for i in range(h):
				a[i][j] = -1
	# print(a)
	for i in range(h):
		for j in range(w):
			if a[i][j] != -1:
				print("{}".format(a[i][j]), end="")
		print("")
if __name__ == '__main__':
	main()

Submission status: Accepted

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

yoko_list=[]
tate_list=[]
for i in range(H):
    for j in range(W):
        if hw[i][j]=="#":
            break
        elif j==W-1:
            yoko_list.append(i)

for i in range(W):
    for j in range(H):
        if hw[j][i]=="#":
            break
        elif j==H-1:
            tate_list.append(i)

for i in range(H):
    if not i in yoko_list:
        p=0
        for j in range(W):
            if not j in tate_list:
                p+=1
                if p==W-len(tate_list):
                    print(hw[i][j])
                else:
                    print(hw[i][j],end="")

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:
X,Y = map(int,input().split())
whole = []
for i in range(X):
  now = input()
  if now == '.' * Y:
    pass
  else:
    add = []
    for i in range(Y):
      if now[i] == '.':
        add.append(0)
      else:
        add.append(1)
    whole.append(add)
j = 0
while j < len(whole[0]):
  for i in range(len(whole)):
    if whole[i][j] == 1:
      j += 1
      break
  else:
    for i in range(len(whole)):
      del whole[i][j]
for i in range(len(whole)):
  now = whole[i]
  ans = ''
  for j in range(len(now)):
    if now[j] == 0:
      ans += '.'
    else:
      ans += '#'
  print(ans)

Submission status: Accepted

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

lst = [input() for i in range(H)]

ans = []
for i in range(W):
	row = [j[i] for j in lst]
	if ("".join(row) != "." * H):
		ans.append("".join(row))

for i in range(H):
	row = [j[i] for j in ans]
	if ("".join(row) != "." * len(row)):
		print("".join(row))

Submission status: Accepted

Solution code:
A=[]
h,w=map(int,input().split())
for i in range(h):
	s=input()
	if s.count("#")!=0:
		A.append(s)
B=[]
C=[]
for i in range(w):
	cnt=0
	for j in range(len(A)):
		if A[j][i]==".":
			cnt+=1
	if cnt==len(A):
		B.append(i)
for i in range(w):
	c=""
	for j in range(len(A)):
		if i not in B:
			c+=A[j][i]
	if len(c)>0:
		C.append(c)
for j in range(len(C[0])):
	p=""
	for i in range(len(C)):
		p+=C[i][j]
	print(p)

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    H, W = (int(_) for _ in input().split())
    a = []
    for i in range(H):
        a.append(list(_ for _ in input()))
    a_1 = []
    for i in range(H):
        if a[i].count('.') != W:
            a_1.append(a[i])
    W_bit = list(1 for _ in range(W))
    for h in range(len(a_1)):
        for w in range(W):
            if a_1[h][w] == '#':
                W_bit[w] = 0    

    for h in range(len(a_1)):
        for w in range(W):
            if W_bit[w] == 0:
                print(a_1[h][w],end='')
        print('')
if __name__ == '__main__':
    main()

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())

C = []

for i in range(H):
    temp = input()

    for i in temp:
        if i != '.':
            C.append(temp)
            break

WB = [0] * W

for i in range(len(C)):
    for j in range(W):
        if C[i][j] == '.':
            WB[j] += 1

for i in range(len(C)):
    for j in range(W):
        if WB[j] != len(C):
            print(C[i][j], end='')
    print()

Submission status: Accepted

Solution code:
H, W = list(map(int,input().split(' ')))
ar = []
for i in range(H):
  w = list(input())
  #print(set(w))
  if set(w) != {'.'}:
    ar.append(w)
    
#print(ar)  

import numpy as np
ar2 = np.array(ar)
ar2_T = ar2.T
ar = []
for i in ar2_T:
#  print(set(i))
  if set(i) != {'.'}:
    ar.append(i)

ar_T = np.array(ar).T
for i in ar_T:
  print(''.join(i))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
h, w = map(int, input().split())


f = lambda s: zip(*[column for column in s if '#' in column])
L = [input() for _ in range(h)]

for row in f(f(L)):
    print(*row, sep='', end='\n')

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
li = []
for i in range(h):
    a = list(input())
    '''
    if all([a[i] == "." for i in range(w)]):
        continue
    else:
        li.append(a)
    '''
    if "#" in a:
      li.append(a)
for j in range(w):
    #if all([li[k][j] == "." for k in range(len(li))]):
    if all(li[k][j] == "." for k in range(len(li))):
        for k in range(len(li)):
            #li[k][j] == ""
            li[k][j] = ""
for m in range(len(li)):
    print("".join(li[m]))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
l = []
for i in range(h):
  x = list(input())
  if "#" in x:
    l.append(x)

for j in range(w):
  if all(l[k][j] == "." for k in range(len(l))):
    for k in range(len(l)):
      l[k][j] = ""
for m in range(len(l)):
  print(''.join(l[m]))

Submission status: Accepted

Solution code:
def row(A):
  B = []
  for a in A:
    if "#" in a:
      B.append(a)
  return B

def trans(A):
  c = len(A[0])
  B = []
  for i in range(c):
    C = ""
    for j in range(len(A)):
      C += A[j][i]
    B.append(C)
  return B

def col(A):
  return trans(row(trans(A)))
        
      

H, W = map(int, input().split())
A = []
for i in range(H):
  A.append(input())

while col(A) != A or row(A) != A:
  A = col(A)
  A = row(A)

for i in A:
  print(i)

Submission status: Accepted

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

a = [x for x in a if "#" in x]
aT = list(zip(*a))
aT = [x for x in aT if "#" in x]
a = list(zip(*aT))

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
l = []
for i in range(h):
  x = list(input())
  if "#" in x:
    l.append(x)
for j in range(w):
  if all(l[i][j] == "." for i in range(len(l))):
    for i in range(len(l)):
      l[i][j] = ""
for i in range(len(l)):
  print(''.join(l[i]))

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(H):
    if "#" not in L[i]:
        for j in range(i, H):
            L[i] = [None] * W
            
for i in range(W):
    f = True
    for j in range(H):
        if L[j][i] == "#":
            f = False
            break
    if f:
        for j in range(H):
            L[j][i] = None
            
for i in range(H):
    f = False
    for j in range(W):
        if L[i][j] != None:
            print(L[i][j], end = "")
            f = True
    if f:
        print()

Submission status: Accepted

Solution code:
 #ABC107, B - grid comprehension
import numpy as np
h, w = map(int, input().split(' '))
A = np.array([list(input()) for i in range(h)])


row_change = 1
col_change = 1
while(row_change == 1 or col_change == 1):
    row_change = 0
    col_change = 0
    row_del = []
    col_del = []

    for i in range(A.shape[0]):
        if all([a == '.' for a in A[i,:]]):
            row_del.append(i)
            row_change = 1
    A = np.delete(A, row_del, 0)

    for j in range(A.shape[1]):
        if all([a == '.' for a in A[:,j]]):
            col_del.append(j)
            col_change = 1
    A = np.delete(A, col_del, 1)

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

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
t = []
for i in range(H):
    x = list(input())
    if "#" in x:
        t.append(x)
for i in range(W):
    if all((t[j][i] == "." for j in range(len(t)))):
        for k in range(len(t)):
            t[k][i] = ""
for i in range(len(t)):
    print("".join(t[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a.append(list(input()))
for i in range(h - 1, -1, -1):
    if a[i] == ["."] * w:
        del a[i]
for i in range(w - 1, -1, -1):
    if [a[j][i] for j in range(len(a))] == ["."] * len(a):
        for j in range(len(a)):
            del a[j][i]
for i in range(len(a)):
    print("".join(a[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [input() for _ in range(h)]
blank_h, blank_w = set(), set()
for i in range(h):
    count = 0
    for j in range(w):
        if a[i][j] != '.':
            break
        count += 1
    if count == w:
        blank_h.add(i)
for j in range(w):
    count = 0
    for i in range(h):
        if a[i][j] != '.':
            break
        count += 1
    if count == h:
        blank_w.add(j)
for i in range(h):
    if i in blank_h:
        continue
    for j in range(w):
        if j in blank_w:
            continue
        print(a[i][j], end='')
    print()

Submission status: Accepted

Solution code:
import numpy as np
h, w = list(map(int, input().split()))
loc_array = [list(input().replace("#", "1").replace(".", "0")) for _ in range(h)]
loc_array = np.array([list(map(int, l)) for l in loc_array])
row_sum = loc_array.sum(axis=1)
col_sum = loc_array.sum(axis=0)
while 0 in row_sum or 0 in col_sum:
  row_rm = [i for i, r in enumerate(row_sum) if r == 0]
  loc_array = np.delete(loc_array, row_rm, axis=0)
  col_rm = [i for i, c in enumerate(col_sum) if c == 0]
  loc_array = np.delete(loc_array, col_rm, axis=1)
  row_sum = loc_array.sum(axis=1)
  col_sum = loc_array.sum(axis=0)

loc_str = [list(map(str, loc_array[i,:])) for i in range(loc_array.shape[0])]
loc_str = ["".join(l).replace("1", "#").replace("0", ".") for l in loc_str]
for l in loc_str:
  print(l)

Submission status: Accepted

Solution code:
import numpy as np
m = []
h, w = map(int, input().split())
for i in range(h):
    arr = list(input())
    if '#' in arr:
        m.append(arr)
    else:
        pass
m = np.array(m).T.tolist()
output = []
for i in range(w):
    if '#' in m[i]:
        output.append(m[i])
    else:
        pass
output = np.array(output).T.tolist()
for i in range(len(output)):
    print(''.join(output[i]))

Submission status: Accepted

Solution code:
def removewhite(l):
  return [item for item in l if all([c=="." for c in item])==False]

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

a=np.array(removewhite(np.array(removewhite(a)).T.tolist()
                      )
          ).T.tolist()
[print("".join(l)) for l in a]

Submission status: Accepted

Solution code:
l = [int(i) for i in input().split(" ")]
h = l[0]
w = l[1]
m = []

def trans(matrix):
    t_matrix = []
    h = len(matrix)
    w = len(matrix[0])
    for i in range(w):
        row = []
        for j in range(h):
            row.append(matrix[j][i])
        t_matrix.append(row)
    return t_matrix

def remove_dot(matrix):
    new_matrix = []
    for row in matrix:
        if "#" not in row:
            pass
        else:
            new_matrix.append(row)
    return new_matrix

for i in range(h):
    m.append(list(input()))
for i in range(2):
    m = remove_dot(m)
    m = trans(m)
for row in m:
    print("".join(row))

Submission status: Accepted

Solution code:
l = [int(i) for i in input().split(" ")]
h = l[0]
w = l[1]

m = []
m_t = []
m_tt = []
# .のみの行を取り除く
for i in range(h):
    row = list(input())
    if "#" not in row:
        pass
    else:
        m.append(row)

# 転置して.のみの行を取り除く
for i in range(w):
    row = []
    for j in range(len(m)):
        row.append(m[j][i])
    if "#" not in row:
        pass
    else:
        m_t.append(row)

# 再び転置する
for i in range(len(m)):
    row = []
    for j in range(len(m_t)):
        row.append(m_t[j][i])
    m_tt.append(row)

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [0] * N
for i in range(N):
    a[i] = list(input())

del_N = []
del_M = []

for i in range(N):
    if a[i].count('.') == M :
        del_N.append(i)

for i in range(M):
    tmp = []
    for j in range(N):
        tmp.append(a[j][i])
    if tmp.count('.') == N:
        del_M.append(i)



ans1 = []
for i in range(N):
    if i not in del_N:
        ans1.append(a[i])



ans2 = [[] for _ in range(len(ans1))]
for i in range(len(ans1)):
    for j in range(M):
        if j not in del_M:
            ans2[i].append(str(ans1[i][j]))



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

Submission status: Accepted

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

table = [[] for _ in range(h)]
skiph = []
skipw = []
for i in range(h):
    table[i] = list(input())
    if len(set(table[i])) == 1:
        if table[i][0] == ".":
            skiph.append(i)

for i in range(w):
    if table[0][i] == ".":
        for j in range(h):
            if table[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
        else:
            print(table[i][j], end="")
    print()

Submission status: Accepted

Solution code:

def rem(a):
    res = []
    for x in a:
        if x.count('#') > 0:
            res.append(x)
    return res

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

while a != rem(a):
    a = rem(a)


a = list(zip(*rem(list(zip(*a)))))

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

Submission status: Accepted

Solution code:
y, x = map(int, input().split())
r = [True] * y
c = [True] * x
z = []
for i in range(y):
    a = input()
    z.append(a)
    for j in range(x):
        if '#' == a[j]:
            c[j] = False
            r[i] = False
for i in range(y):
    if r[i] == False:
        for j in range(x):
            if c[j] == False:
                print(z[i][j], end='')
        print()

Submission status: Accepted

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

l = []
for i in range(w):
    s = ""
    for j in range(len(grid)):
        f = grid[j]
        s = s+f[i]
    if "#" in s:
        l.append(s)

ans = []
for i in range(len(l[0])):
    s = ""
    for j in range(len(l)):
        f = l[j]
        s = s+f[i]
    ans.append(s)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    A = [[c for c in input()] for _ in range(H)]
    sniprows = set()
    for i in range(H):
        snip = True
        for j in range(W):
            if A[i][j] == "#":
                snip = False
        if snip:
            sniprows.add(i)
    snipcols = set()
    for j in range(W):
        snip = True
        for i in range(H):
            if A[i][j] == "#":
                snip = False
        if snip:
            snipcols.add(j)
    for i in range(H):
        if i in sniprows:
            continue
        ans = ""
        for j in range(W):
            if j in snipcols:
                continue
            ans += A[i][j]
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    l = input()
    if any([c == '#' for c in l]):
        A.append(l)

for j in range(W):
    if all([a[j] == '.' for a in A]):
        for i in range(len(A)):
            A[i] = A[i][:j] + '*' + A[i][j + 1:]
for a in A:
    print(a.replace('*', ''))

Submission status: Accepted

Solution code:
# 黒がある行と列を把握すればいい。
def ch(info,w): #もらったリストに黒が入ってるかを確認
    c=0
    for i in range(w):
        if info[i]=="#":
            c=1
            break
    return c

h,w=map(int,input().split())
info=[]
black=[]
hl=0
for i in range(h):
    s=list(input())
    if ch(s,w)==1:
        info.append(s)
        hl+=1
#print(info)
for i in range(hl):
    for j in range(w):
        if info[i][j]=="#":
            black.append(j)
for i in range(hl):
    for j in range(w):
        if j in black:
            print(info[i][j],end="")
    print("\n")

Submission status: Accepted

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

li= np.array([input() for _ in range(h)])
del_count= 0
for i in range(h):
     if li[i-del_count] == "." * w:
         li = np.delete(li, i-del_count, 0)
         del_count+=1

del_count = 0
for i in range(len(li[0])):
    for j in range(len(li)):
        if li[j][i-del_count] == "#":
            break
        elif j == len(li)-1:
            for k in range (len(li)):
                li[k] = li[k][:i-del_count]+li[k][i-del_count+1:]
            del_count+= 1
for i in li:
    print(i)

Submission status: Accepted

Solution code:
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())

ans = []
for i in range(h):
    temp = input()
    if '#' not in temp:
        continue
    ans.append(temp)

for i in reversed(range(w)):
    if ans[0][i] == '.':
        flag = True
        for j in range(len(ans)):
            if ans[j][i] != '.':
                flag = False
                break

        if flag:
            for j in range(len(ans)):
                ans[j] = ans[j][:i] + (ans[j][i+1:len(ans[j])] if i+1 < len(ans[j]) else '')

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