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

H, W = map(int,input().split())
board = [[str(c) for c in l.strip()] for l in stdin]
np_board = np.array(board)
np_board = np_board[:, np.any(np_board == "#", axis=0)]
np_board = np_board[np.any(np_board == "#", axis=1), :]

for i in range(np_board.shape[0]):
  for j in range(np_board.shape[1]):
    print(np_board[i][j], end="")
  print("")

Submission status: Accepted

Solution code:
# ABC107B - Grid Compression
h, w = list(map(int, input().rstrip().split()))
data = [input().rstrip() for _ in range(h)]
row = [False] * h
col = [False] * w

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

for i in range(h):
    if row[i] == True:
        for j in range(w):
            if col[j] == True:
                print(data[i][j], end="")
        print()

Submission status: Accepted

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

a=[]
for _ in range(H):
  w = input()
  if w != '.'*W:
    a.append(w)
  else:
    continue

b=[]
for i in range(W):
  c = ""
  for j in range(len(a)):
    c += a[j][i]
  if c != '.'*len(a):
    b.append(c)
  else:
    continue

d=[]
for i in range(len(b[0])):
  e = ""
  for j in range(len(b)):
    e += b[j][i]
  d.append(e)

print('\n'.join(d))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]



def main():
    h, w = readIntN()
    a = []
    for _ in range(h):
        s = input()
        if list(set(s)) != ['.']:
            a.append(s)
    r = []
    for i in range(w):
        ll = [s[i] for s in a]
        if len(set(ll)) == 1 and '.' in ll:
            continue
        r.append(ll)

    for j in range(len(r[0])):
        u = [r[i][j] for i in range(len(r))]
        print(''.join(u))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

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

a = np.array(a)

i = 0
j = 0


while i < len(a):
    if np.sum(a[i,:] == '#') == 0:
        a = np.delete(a, i, 0)
        i -=1
    i +=1

while j < w:
    if np.sum(a[:,j] == '#') == 0:
        a = np.delete(a, j, 1)
        j -= 1
    j += 1
    h, w = a.shape



h, w = a.shape
for i in range(h):
    for j in range(w):
        print(a[i, j], end="")
    print('')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[s for s in [input() for i in range(h)] if "#" in s]
l=[]
for i in range(w):
    if all([a[k][i]=="." for k in range(len(a))]):
        l.append(i)
for i in l[::-1]:
    for j in range(len(a)):
       a[j]=a[j][:i]+a[j][i+1:]
for i in range(len(a)):
    print(a[i])

Submission status: Accepted

Solution code:
import numpy as np
H,W = map(int,input().split(' '))
X = []
for i in range(H):
  X.append(list(input()))
X = np.array(X)
a = X[:,~np.all(X == '.',axis=0)]
b = a[~np.all(a == '.',axis=1),:]
for i in b:
  print(''.join(i))

Submission status: Accepted

Solution code:
[H,W] = list(map(int,input().split()))
A = [input() for i in range(H)]
row = []
col = []
for i in range(H):
  all_white = True
  for j in range(W):
    if A[i][j] == "#":
      all_white = False
  if all_white:
    row.append(i)
for j in range(W):
  all_white = True
  for i in range(H):
    if A[i][j] == "#":
      all_white = False
  if all_white:
    col.append(j)
for i in range(H):
  if i in row:
    continue
  for j in range(W):
    if j in col:
      continue
    print(A[i][j],end="")
  print()

Submission status: Accepted

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

col = [i for i in range(len(grid[0]))]
for j in range(len(grid[0])):
    for i in range(len(grid)):
        if grid[i][j] == "#":
            break
    else:
        continue
    col.remove(j)

for g in grid:
    for c in col[::-1]:
        g.pop(c)
    print(*g, sep='')

Submission status: Accepted

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

row = [False for i in range(H)]
col = [False for i in range(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] == True:
        for j in range(W):
            if col[j] == True:
                print(a[i][j],end="")
        print()

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)
a = zip(*[i for i in zip(*a) if "#" in i])
for i in a:
    print(*i, sep="")

Submission status: Accepted

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

data = []
for i in range (H):
    temp = list(input())
    data.append(temp)

data = np.array(data)

h_true = []
for i in range (H):
    if (('#' not in data[i])  & ('.' in data[i])) == True:
        h_true.append(i)

w_true = []
for j in range (W):
    if (('#' not in data[:,j])  & ('.' in data[:,j])) == True:
        w_true.append(j)

data = np.delete(data,h_true,0)
data = np.delete(data,w_true,1)

for k in range (data.shape[0]):
    print(''.join(data[k]))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
a = []
for i in range(H):
    L = list(input())
    a.append(L)
delH,delW = [],[]
for i in range(H):
    if all(a[i][j]=='.' for j in range(W)):
        delH.append(i)
for j in range(W):
    if all(a[i][j]=='.' for i in range(H)):
        delW.append(j)
for i in range(H):
    for j in range(W):
        if i not in delH and j not in delW:
            print(a[i][j], end="")
    if i not in delH:
        print()

Submission status: Accepted

Solution code:
H, W = map(int, input().rstrip().split())
a = [list(input()) for _ in range(H)]
a_int = []
for i in range(H):
    tmp = [1 if a[i][j] == "#" else 0 for j in range(W)]
    a_int.append(tmp)
column = []
row = []
for i in range(H):
    if sum(a_int[i])==0:
        row.append(i)
for i in range(W):
    total = 0
    for j in range(H):
        total += a_int[j][i]
    if total == 0:
        column.append(i)
row.reverse()
column.reverse()
for i in row:
    a.pop(i)
for i in column:
    for j in range(len(a)):
        a[j].pop(i)
for S in a:
    print(*S, sep ="")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
c=[]
for i in range(H):
  ci=input()
  if ci=="."*W:
    continue
  c.append(ci+"#")
l=len(c)
k=[True]*(W+1)
for i in range(l):
  for j in range(W,-1,-1):
    k[j]=k[j] and (c[i][j]==".")

for i in range(l):
  for j in range(W,-1,-1):
    if k[j]:
      c[i]=c[i][0:j]+c[i][j+1:]
for i in range(l):
  print(c[i][:-1])

Submission status: Accepted

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

f_row = []
f_col = []
for i in range(h):
    for j in range(w):
        if a[i][j] != '.':
            break
        if j == w-1:
            f_row.append(i)
for j in range(w):
    for i in range(h):
        if a[i][j] != '.':
            break
        if i == h-1:
            f_col.append(j)

for i in range(h):
    if i in f_row:
        continue
    for j in range(w):
        if j not in f_col:
            print(a[i][j], end='')
    print()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
	
def main():
	H, W = map(int, input().split())
	chk = "." * W
	A = []
	for _ in range(H):
		tmp = input()
		if tmp != chk:
			A.append(list(tmp))
		else:
			H -= 1
			
	del_list = []
	for i in range(W):
		del_ok = True
		for j in range(H):
			if "." != A[j][i]:
				del_ok = False
				break
		if del_ok == True:
			del_list.append(i)
			
	ans = []
	line = ""
	for i in range(H):
		line = ""
		for j in range(W):
			if j in del_list:
				continue
			line += A[i][j]
		print(line)
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

tate = set(range(H))
yoko = set(range(W))

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            break
    else:
        tate.remove(i)

for i in range(W):
    for j in range(H):
        if A[j][i] == "#":
            break
    else:
        yoko.remove(i)

B=[[A[i][j] for i in tate] for j in yoko]
C=[""]*(len(list(tate)))

for i in range(len(list(tate))):
    for j in range(len(list(yoko))):
        C[i] += B[j][i]

for i in range(len(list(tate))):
    print(C[i])

Submission status: Accepted

Solution code:
import numpy as np

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

for i in range(H):
  line = list(input())
  grid.append(line)

mod_grid = []
for i in range(H):
  if '#' in grid[i]:
    mod_grid.append(grid[i])
    
mod_grid = np.array(mod_grid).T
mod_grid2 = []
for i in range(W):
  if '#' in mod_grid[i]:
    mod_grid2.append(mod_grid[i])
    
mod_grid2 = np.array(mod_grid2).T
for i in range(mod_grid.shape[1]):
  if '#' in mod_grid2[i]:
    print(''.join(mod_grid2[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [str(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:


def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    for i in range(high)[::-1]:
        if data[i].count('#') == 0:
            data.pop(i)

    for i in range(width)[::-1]:
        flg = 1
        for j in range(len(data)):
            if data[j][i] == '#':
                flg = 0
                break
        if flg:
            for j in range(len(data)):
                data[j].pop(i)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ccheck = 0
for i, l in enumerate(STAGE):
	ccheck |= int(l.replace("#", "1").replace(".", "0"), 2)

for l in STAGE:
	if "#" not in l:
		continue
	for f, c in zip(format(ccheck, "b").zfill(W), l):
		if "1" == f:
			print(c, end="")
	print("")

Submission status: Accepted

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

for i in range(N):
    #print(a[i])
    if a[i].count('#') == 0:
        delMlist.append(i)
#print(delMlist)

for i in delMlist:
    a.pop(i-counter)
    #print(a)
    counter += 1
#print('---------')
#print(a)
N = N - len(delMlist)
#print(N)
newlist = []
for i in range(N):   
    for j in range(M):
        if a[i][j] == '.' :
            numlist.append([i,j])
    newlist.append([a[i]])
llist = []
for i in range(N):
    #llist = list(a[i])
    llist.append(list(a[i]))
#print(llist)
counter1 = 0
fst = ''
delNlist = []
#print(N)
for i in range(M):
    for j in range(N):
        #print(j)
        if llist[j][i] == '.':
            counter1 += 1
        if counter1 == N:
            delNlist.append(i)
    counter1 = 0
#print(delNlist)
#print('---------')
#anslist = []
counter2 = 0
if delNlist != []:
    for h in delNlist:
        for i in range(N):
            a[i] = (a[i][:h-counter2] + a[i][h+1-counter2:])
        counter2 += 1
for i in a:
    print(i)
#print(a)

Submission status: Accepted

Solution code:
import sys

h, w = map(int, input().split())
a_list = []

for i in range(h):
    tmp = input()
    if '#' in tmp:
        a_list.append(list(tmp))

del_list = []

for i in range(w):
    tmp = ''
    for j in a_list:
        tmp += j[i]
    if not '#' in tmp:
        del_list.append(i)

for i in del_list[::-1]:
    for j in range(len(a_list)):
        a_list[j].pop(i)

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(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):
    s = input()
    if '#' in s:
        a.append(s)

new_a =[]

for i in range(W):
    for j in range(len(a)):
        if a[j][i] == '#':
            s = ""
            for k in range(len(a)):
                s += a[k][i]
            new_a.append(s)
            break

for i in range(len(new_a[0])):
    s = ""
    for j in range(len(new_a)):
        s += new_a[j][i]
    print(s)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
arr = [input() for j in range(h)]
tarr = []
counter = 0
for i in range(h):
    if arr[i].count("#") != 0:
        counter += 1
        tarr.append(arr[i])
tans = [["" for i in range(counter)] for j in range(w)]
for i in range(counter):
    for j in range(w):
        tans[j][i] = tarr[i][j]
counter2 = 0
ttans = []
for i in range(w):
    if tans[i].count("#") != 0:
        counter2 += 1
        ttans.append(tans[i])
for i in range(counter):
    for j in range(counter2):
        print(ttans[j][i], end="")
        if j == counter2-1:
            print("")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
arr = [input() for j in range(h)]
tarr = []
counter = 0
for i in range(h):
    buf = arr[i]
    if buf.count("#") != 0:
        counter += 1
        tarr.append(buf)
tans = [["" for i in range(counter)] for j in range(w)]
for i in range(counter):
    for j in range(w):
        tans[j][i] = tarr[i][j]
counter2 = 0
ttans = []
for i in range(w):
    buf = tans[i]
    if buf.count("#") != 0:
        counter2 += 1
        ttans.append(buf)
for i in range(counter):
    for j in range(counter2):
        print(ttans[j][i], end="")
        if j == counter2-1:
            print("")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def solve(h, w, a):
    ret = []
    for r in a:
        left = False
        for c in r:
            if c == '#':
                left = True
                break
        if left:
            ret.append(r)
    ret2 = ['' for _ in range(len(ret))]
    for j in range(w):
        left = False
        for i in range(len(ret)):
            if ret[i][j] == '#':
                left = True
                break
        if left:
            for i in range(len(ret)):
                ret2[i] += ret[i][j]
    for r in ret2:
        print(r)
    return


def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(str(input()))
    solve(h, w, a)
    # Failed to predict input format
    pass

if __name__ == '__main__':
    main()

Submission status: Accepted

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

num_col_white = [0] * W
for i in range(H):
  for j in range(W):
    if A[i][j] == '.':
      num_col_white[j] += 1

for i in range(H):
  if A[i].count('.') == W:
    continue
  row = ''
  for j in range(W):
    if num_col_white[j] != H:
      row += A[i][j]
  print(row)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
T=[list(input()) for i in range(h)]
while ["."]*w in T:
  T.remove(["."]*w)
  h-=1
T=list(list(i) for i in zip(*T))
while ["."]*h in T:
  T.remove(["."]*h)
T=list(list(i) for i in zip(*T))
for t in T:
  print("".join(t))

Submission status: Accepted

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

#.だけの行を省いてrowsに格納
for r in rs:
  if '#' in r: rows.append(r)

ansrows = zip(*[c for c in zip(*rows) if '#' in c])

for r in list(ansrows):
  print(''.join(r))

Submission status: Accepted

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

rows = [] #最初のfor文で、..だけの行を除く行を格納

for i in range(h):
  row = input()
  for c in row:
    if c == '#':
      rows.append(row)
      break
      
columns = []
column = ''
for i in range(w): #各列に対して行う
  for j in range(len(rows)): #行の数、つまり列の長さ
    if rows[j][i:i+1] == '#':
      for k in range(len(rows)):
        column += rows[k][i:i+1]
      columns.append(column)
      column = ''
      break
      
r = len(columns[0]) #最終行の数
ansrows = [''] * r
for i in range(r): #最終行の数だけ
  for j in range(len(columns)): #最終列の数だけ
  	ansrows[i] += columns[j][i]

#解答
for ans in ansrows: print(ans)

Submission status: Accepted

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

def compress(b, h, w):
  b = [c for c in b if '#' in c]
  b = [''.join(x) for x in zip(*b)]
  b = [c for c in b if '#' in c]
  b = [''.join(x) for x in zip(*b)]
  if len(b) == h and len(b[0]) == w:
    return b
  return compress(b, len(b), len(b[0]))

r = compress(a, H, W)
for i in range(len(r)):
  print(r[i])

Submission status: Accepted

Solution code:
h,w=map(int,input().split());print(*["".join(e)for e in zip(*["".join(e)for e in zip(*[e for e in[input()for _ in[0]*h]if"#"in e])if"#"in e])],sep="\n")

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())
a=[]
for i in range(H):
    ai=input()
    if ai=="."*W:
        continue
    a.append(ai)
h=len(a)
def tenti(a):
    b=[]
    h=len(a)
    w=len(a[0])
    for i in range(w):
        bi=[]
        for j in range(h):
            bi.append(a[j][i])
        b.append(bi)
    return b
b=tenti(a)
h=len(b)
w=len(b[0])
c=[]
for i in range(h):
    if b[i]==["."]*w:
        continue
    c.append(b[i])
d=tenti(c)
for i in range(len(d)):
    for j in range(len(d[0])):
        if j==len(d[0])-1:
            print(d[i][j])
            break
        print(d[i][j],end="")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

# あー､ループの中で元の配列を変えちゃってるからエラー出てたのか

a_new = list()

for i, li  in enumerate(a):
    if a[i].count('.')  != w:
        a_new.append(a[i])

b = [list(i) for i in zip(*a_new)]


b_new = list()

for i, li  in enumerate(b):
    if b[i].count('.')  != len(b[0]):
        b_new.append(b[i])

c = [list(i) for i in zip(*b_new)]
for i in c:
    print(''.join(i))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = []
B = []
for i in range(H):
    a = list(input())
    if a != ["."]*W:
        A.append(a)
for i in range(W):
    cnt = 0
    for j in range(len(A)):
        if A[j][i] != '.':
            cnt += 1
    if cnt == 0:
        B.insert(0,i)
for i in range(len(A)):
    for j in range(len(B)):
        del A[i][B[j]]
for i in range(len(A)):
    ans = "".join(A[i])
    print(ans)

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
A = []
B = []
for i in range(H):
  a = list(input())
  if a != ["."]*W:
    A.append(a)
for i in range(W):
  cnt = 0
  for j in range(len(A)):
    if A[j][i] != ".":
      cnt += 1
  if cnt == 0:
    B.insert(0,i)
for i in range(len(A)):
  for j in range(len(B)):
    del A[i][B[j]]
for i in range(len(A)):
  ans = "".join(A[i])
  print(ans)

Submission status: Accepted

Solution code:
def generate_transposed_grid(grid):
    t_grid = [[None] * len(grid) for i in range(len(grid[0]))]
    for i in range(len(grid)):
        for j in range(len(grid[0])):
            t_grid[j][i] = grid[i][j]
    return t_grid


def generate_compressed_grid(grid):
    return [s for s in grid if not s == ['.'] * len(s)]


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

for _ in range(2):
    grid = generate_compressed_grid(grid)
    grid = generate_transposed_grid(grid)

for s in grid:
    print(''.join(s))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
mapli = []
for i in range(H):
    tmp = []
    s = str(input())
    for j in range(W):
        tmp.append(s[j])
    mapli.append(tmp)

tmp = []

for i in range(H):
    count = 0
    for j in range(W):
        if mapli[i][j] == ".":
            count += 1
    if count == W:
        tmp.append(i)
tmp.sort(reverse=True)

for i in range(len(tmp)):
    del mapli[tmp[i]]

tmp = []

for i in range(W):
    count = 0 
    if mapli[0][i] == ".": 
        for j in range(len(mapli)):
            if mapli[j][i] != ".":
                break
            count += 1
    if count == len(mapli):
        tmp.append(i)
tmp.sort(reverse=True)

for i in range(len(tmp)):
    for k in range(len(mapli)):
        del mapli[k][tmp[i]]

for i in range(len(mapli)):
    print(''.join(map(str, mapli[i])))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
b=[list(input()) for _ in range(h)]
for i in range(h-1,-1,-1):
  if b[i].count('.')==w:
    del b[i]
    h-=1
for i in range(w-1,-1,-1):
  count=0
  for j in range(h):
    if b[j][i]=='.':
      count+=1
  if count==h:
    for j in range(h):
      tmp=b[j][:i]+b[j][i+1:]
      b[j]=tmp
for i in range(h):
  print(''.join(b[i]))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
hw = [list(input()) for j in range(h)]
tf = [True for i in range(w)]
ans = []
for i in hw:
  if i.count(".") != w:
    ans.append(i)
  for j in range(len(i)):
    if i[j]=="#":
      tf[j] = False
for i in range(len(ans)):
  for j in range(len(tf)):
    if not tf[j]:
      print(ans[i][j],end='')
  print('')

Submission status: Accepted

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

box = []
for i in range(H):
    a = [j for j in input()]
    if all(j == '.' for j in a):
        pass
    else:
        box.append(a)

idx = []
for i in range(len(box[0])):
    ct = 0
    for j in box:
        if j[i] == '.':
            ct += 1
    if ct == len(box):
        idx.append(i)

for i in box:
    for j in range(len(i)):
        if j < len(i)-1:
            if j in idx:
                pass
            else:
                print(i[j], end='')
        else:
            if j in idx:
                print()
            else:
                print(i[j])

Submission status: Accepted

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

sharp = []
for i in range(W):
    flg = 0
    for j in range(len(a)):
        if a[j][i] == '#':
            flg = 1
    if flg == 1:
        sharp.append(i)

for i in range(len(a)):
    ans = ''
    for j in sharp:
        ans += a[i][j]
    print(ans)

Submission status: Accepted

Solution code:
def main():
	H, W = map(int, input().split())
	a = [["." for _ in range(W)] for _ in range(H)]
	ans = []
	is_column_white = [True]*H
	is_row_white = [True]*W
	for i in range(H):
		row = input()
		for j in range(W):
			a[i][j] = row[j]
			if row[j] == "#":
				is_column_white[i]=False
				is_row_white[j] = False

	for i in range(H):
		if is_column_white[i]:
			continue
		ans_row = ""
		for j in range(W):
			if is_row_white[j]:
				continue
			ans_row += a[i][j]
		print(ans_row)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
ys,xs=set(),set()
for y in range(h):
	for x in range(w):
		if a[y][x] == "#":
			ys.add(y)
			xs.add(x)
for y in sorted(list(ys)):
	for x in sorted(list(xs)):
		print(a[y][x], end="")
	print("")

Submission status: Accepted

Solution code:
import numpy as np

n,m=map(int,input().split())

hoge=[]
huga=[]
hago=[]
h=0
w=0
for i in range(n):
  hoge.append(list(input()))

for i in range(n):
  if(hoge[i].count("#")!=0):
    h+=1
    huga.append(hoge[i])
    
hoge=np.array(huga).T.tolist()

for i in range(m):
  if(hoge[i].count("#")!=0):
    w+=1
    hago.append(hoge[i])
    
hago=np.array(hago).T.tolist()
    
for i in range(h):
  for j in range(w):
    print(hago[i][j],end="")
  print("")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

# あー､ループの中で元の配列を変えちゃってるからエラー出てたのか

a_new = list()

for i, li  in enumerate(a):
    if a[i].count('.')  != w:
        a_new.append(a[i])

b = [list(i) for i in zip(*a_new)]


b_new = list()

for i, li  in enumerate(b):
    if b[i].count('.')  != len(b[0]):
        b_new.append(b[i])

c = [list(i) for i in zip(*b_new)]
for i in c:
    print(''.join(i))

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

mask = A=='.'

row_idx = np.logical_not(np.all(mask, axis=1))
col_idx = np.logical_not(np.all(mask, axis=0))

for a in A[row_idx][:, col_idx]:
    print(''.join(list(a)))

Submission status: Accepted

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

for h in range(H):
    a[h] = [inp for inp in input()]
#print(a)
check = [[0] * W for _ in range(H)]

for h in range(H):
    for w in range(W):
        if a[h][w] == '#':
	        check[h][w] = 1
#print(a)
#print(check)
final_w = [0] * W
for h in range(H):
    final_w = [final_w[w] + check[h][w] for w in range(W)]
    
final_h = [0] * H
for w in range(W):
    final_h = [final_h[h] + check[h][w] for h in range(H)]
  
#print(final)
for h in range(H):
    res = ''
    for w in range(W):
        if final_w[w] >= 1 and final_h[h] >= 1:
            res += a[h][w]
    print(res + '\n')

Submission status: Accepted

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

for i in range(H):
        bd.append(input())

x=set()
y=set()

for i in range(H):
        for j in range(W):
                if bd[i][j]=="#":
                        x.add(j)
                        y.add(i)
for i in y:
        for j in x:
                print(bd[i][j],end="")
        print()

Submission status: Accepted

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

for i in range(H):
    bd.append(input())

x = set()
y = set()
for i in range(H):
    for j in range(W):
        if bd[i][j] == '#':
            x.add(j)
            y.add(i)

for i in y:
    for j in x:
        print(bd[i][j], end='')
    print()

Submission status: Accepted

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

new_data = []
row = [0] * W
for d in data:
    if d.count('.') == W:
        continue
    new_data.append(d)
    for i in range(W):
        if d[i] == '.':
            row[i] += 1

num = len(new_data)

for d in new_data:
    for i in range(W):
        if row[i] != num:
            print(d[i], end='')
    print()

Submission status: Accepted

Solution code:
h, k = map(int, input().split())
mat = [input() for _ in range(h)]
for _  in range(2):
    poplist = []
    for i, row in enumerate(mat):
        for x in row:
            if x == '#':
                break
        else:
            poplist.append(i)
    poplist.reverse()
    for i in poplist:
        mat.pop(i)
    poplist = []
    mat = [x for x in zip(*mat)]
for row in mat:
    print(''.join(row))

Submission status: Accepted

Solution code:
f=lambda s:zip(*[t for t in s if'#'in t]);print(*map(''.join,f(f(open(0)))))

Submission status: Accepted

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

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

while True:
    b=a
    for i in range(len(a)-1,-1,-1):
        if not "#" in a[i]: a.pop(i)   

    for j in range(len(a[0])-1,-1,-1):
        if all(a[i][j]=="." for i in range(len(a))):
            for i in range(len(a)):
                a[i]=a[i][:j]+a[i][j+1:]


    if b==a: break

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

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, raw_input().split())
a = []
for i in range(h):
	tmp_a = list(raw_input())
	tmp_a = [1 if j == '#' else 0 for j in tmp_a]
	a.append(tmp_a)
a = np.array(a)
y0, x0 = a.shape
for i in range(x0 + y0):
	a = a[np.any(a == 1, axis=1)]
	a = a[:, np.any(a == 1, axis=0)]
	y, x = a.shape
	if (x0 == x) & (y0 == y):
		break
	else:
		x0, y0 = x, y
a = a.tolist()
for i in range(y):
	ans = ['#' if j == 1 else '.' for j in a[i][:]]
	print ''.join(ans)

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=map(int,input().split())
A=[]
indh=[]
indw=[]
A=[list(input()) for _ in range(H)]   
for i in reversed(range(H)):
    if set(A[i])==set('.'):
        A.pop(i)
import numpy as np
AT=list(np.array(A).T)
ansT=[]
for i in range(W):
    if set(AT[i])!=set('.'):
        ansT.append(AT[i])
for a in list(np.array(ansT).T):
    print(''.join(a))

Submission status: Accepted

Solution code:
import numpy as np
h,w = map(int,input().split())
a_list = [list(input()) for _ in range(h)]
res = []
for a in a_list:
    if set(a) != set('.'):
        res.append(a)
res = list(np.array(res).T)
resT = []
for a in res:
    if set(a) != set('.'):
        resT.append(a)
for a in list(np.array(resT).T):
    print(''.join(a))