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:
n,m = map(int, raw_input().split())
mat = []
for i in xrange(n):
    mat.append(list(raw_input()))

l = [[0 for i in xrange(m)] for j in xrange(n)]

for i in xrange(n):
    flag = 0
    for j in xrange(1,m):
        if mat[i][j] != mat[i][0]:
            flag = 1
    if flag or mat[i][0] != '.':
        for j in xrange(m):
            l[i][j] = 1


for i in xrange(m):
    flag = 0
    for j in xrange(1,n):
        if mat[j][i] != mat[0][i]:
            flag = 1

    if not flag and mat[0][i] == '.':
        for j in xrange(n):
            l[j][i] = 0



for i in xrange(n):
    s = ''
    for j in xrange(m):
        if l[i][j]:
            s += mat[i][j]
    if s != '':
        print s

Submission status: Accepted

Solution code:
def abc107_b():
    import numpy as np

    h, w = map(int, input().split())
    a = []
    for i in range(h):
        tmp = list(input())
        if not tmp == ["."] * w:
            a = np.append(a, tmp)
    a = a.reshape((-1, w))

    return a[:, np.any(a != np.array(["."] * w), axis=0)]

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

Submission status: Accepted

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

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

newmat = []

for i in range(H):
    if matrix[i] == '.'*W:
        continue
    else:
        newmat.append(matrix[i])
        
printW = []
for x in range(W):
    for lin in newmat:
        if lin[x] == '#':
            printW.append(x)
            break
        
for lin in newmat:
    str = ''
    for w in printW:
        str += lin[w]
    print(str)

Submission status: Accepted

Solution code:
import numpy as np
import math


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

A = np.zeros((H, W), dtype=int)

for h in range(H):
    ah = input()
    for w in range(W):
        if ah[w] == '.':
            A[h][w] = 0
        else:
            A[h][w] = 1

# print(A)
remH = []
remW = []
            
for h in range(H):
    if all(A[h] == 0):
        remH.append(h)
for w in range(W):
    if all(A[:,w] == 0):
        remW.append(w)

# print(remH, remW)
        
ret = []

for h in range(H):
    if h in remH:
        continue
    hlist = []
    for w in range(W):
        if w in remW:
            continue
        # print(h)
        # print(w)
        # print(A[h][w])
        hlist.append(A[h][w])
    ret.append(hlist)

# print(ret)

retH = H - len(remH)
retW = W - len(remW)

# print(retH, retW)
for x in range(retH):
    for y in range(retW):
        if ret[x][y] == 0:
            print('.', end='')
        else:
            print('#', end='')            
    print()

Submission status: Accepted

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

aa = []
for i in range(h):
    if a[i] != ["."]*w:
         aa.append(a[i])
        

import numpy as np

aaa = np.array(aa)

aaaa=[]
for i in range(aaa.T.shape[0]):
    if "".join(aaa.T[i]) != "."*aaa.T.shape[1]:
         aaaa.append(aaa.T[i])
            
tm = np.array(aaaa).T

for i in range(tm.shape[0]):
    print("".join(tm[i]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    l = list(input())
    if not all(a=='.' for a in l):
        A.append(l)
d = []
for i in range(W):
    if all(aa[i]=='.' for aa in A):
        d.append(i)

B = []
for aa in A:
    l = ''
    for i, a in enumerate(aa):
        if i not in d:
            l += a
    B.append(l)
        
for bb in B:
    print(bb)

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
A = [[0 for _ in range(W+1)] for _ in range(H+1)]
for h in range(H):
  l = input()
  for w in range(W):
    A[h][w] = 0 if l[w] == '.' else 1
for h in range(H):
  n = 0
  for w in range(W):
    n += A[h][w]
  A[h][W] = n
for w in range(W):
  n = 0
  for h in range(H):
    n += A[h][w]
  A[H][w] = n
for h in range(H):
  if A[h][W] == 0: continue
  ans = []
  for w in range(W):
    if 0 < A[H][w]:
      ans.append('.' if A[h][w] == 0 else '#')
  print(''.join(map(str,ans)))

Submission status: Accepted

Solution code:
a = input().split()
h = int(a[0])
w = int(a[1])

m = []
for i in range(h):
	sb = input()
	if not  sb == '.'*w:
		m.append(sb)
			
if not m == []:
	output = [[] for i in range(len(m))]
	for i in range(len(m[0])):
		notok = True
		for j in range(len(m)):
			notok = notok and (m[j][i] == '.')
			if notok == False:
				break
		if notok == False:
			for j in range(len(m)):
				output[j].append(m[j][i])
				
for i in range(len(output)):
	print(''.join(output[i]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
li = []
for i in range(H):
	x = input()
	if "#" in x:
		li.append(x)

H = len(li)
W = len(li[0])

removelist = []
for i in range(W):
	for j in range(H):
		if li[j][i] == "#":
			break
	else:
		removelist.append(i)

for i in reversed(removelist):
	for j in range(H):
		li[j] = li[j][:i] + li[j][i+1:]

for i in range(H):
	print(li[i])

Submission status: Accepted

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

a = []

for i in range(h):
    str_list = input()
    a_list = [0 if j == "." else 1 for j in str_list]
    a.append(a_list)

i = 0
while i < h:
    if i > len(a)-1:
        break
    if sum(a[i]) == 0:
        a.pop(i)
        i-=1
    i+=1


i = 0
while i < w:
    if i > len(a[0])-1:
        break
    if sum([a[j][i] for j in range(len(a))]) == 0:
        for j in range(len(a)):
            a[j].pop(i)
        i-=1
    i+=1


for i in range(len(a)):
    outlist = ["." if a[i][j] == 0 else "#" for j in range(len(a[0]))]
    str_list = ""
    for j in outlist:
        str_list+=j
    print(str_list)

Submission status: Accepted

Solution code:
def linecheck(a,i):
    for j in range(W):
        if a[i][j] != ".":
            return False
    return True
def colcheck(a,j,H):
    for i in range(H):
        if a[i][j] != ".":
            return False
    return True
H,W = map(int,input().split())
a = []
for i in range(H):
    a.append(list(input()))
i = 0
while i<H:
    if linecheck(a,i):
        del a[i]
        i = 0
        H -= 1
    else:
        i += 1
j = 0
while j<W:
    if colcheck(a,j,H):
        for i in range(H):
            del a[i][j]
        j = 0
        W -= 1
    else:
        j += 1
for i in range(H):
    print("".join(a[i]))

Submission status: Accepted

Solution code:
H, M = map(int, input().split())
matrix = []
for i in range(H):
    matrix.append([_ for _ in list(map(str, input()))])

bad_row = set()
bad_column = set()
for i in range(H):
    if all([x == '.' for x in matrix[i]]):
        bad_row.add(i)

for j in range(M):
    tmp = [matrix[i][j] for i in range(H)]
    if all([x == '.' for x in tmp]):
        bad_column.add(j)

for i in range(H):
    for j in range(M):
        if i not in bad_row:
            if j not in bad_column:
                print(matrix[i][j], end='')
    if i not in bad_row:
        print('')

Submission status: Accepted

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

a2 = []
for item in a:
    if item == "." * W: continue
    a2.append(item)

white = []
for j in range(W):
    for item in a2:
        if item[j] == "#": break
        else: continue
    else:
        white.append(j)

a3 = []
for item in a2:
    line = ""
    for j in range(W):
        if j in white: continue
        line += item[j]
    a3.append(line)

for item in a3: print(item)

Submission status: Accepted

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

x = []
for i in range(h):
    x.append(input())

x2  = []
for i in x:
    if '#' in i:
        x2.append(i)

de = []

for i in range(w):
    flag = 0
    for line in x2:
        if line[i] == '#':
            flag = 1
            break
    if flag == 0:
        de.append(i)

for line in x2:
    st = ""
    for i in range(w):
        if i in de:
            pass
        else:
            st += line[i]
    print(st)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = []
for i in range(h):
    s = input()
    if s != "." * w:
        A.append(s)

h = len(A)
white_col_index = []
for j in range(w):
    s = "".join([A[i][j] for i in range(h)])
    if s == "." * h:
        white_col_index.append(j)

output_col_index = sorted(list(set(range(w)) - set(white_col_index)))
for i in range(h):
    print("".join(A[i][j] for j in output_col_index))

Submission status: Accepted

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

row_space = []
col_space = []

for k, row in enumerate(A):
    if '#' not in row:
        row_space.append(k)

A_rot = numpy.rot90(A, k=-1)
for k, row in enumerate(A_rot):
    if '#' not in row:
        col_space.append(k)

A = numpy.delete(A, row_space, axis=0)
A = numpy.delete(A, col_space, axis=1)
ans = '\n'.join([''.join(row) for row in A])
print(ans)

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
A = [input() for k in range(H)]
B = []
for k in range(len(A)):
    if A[k] != "."*W:
        B.append(A[k])

C = []
for k in range(len(B[0])):
    T = ""
    for l in range(len(B)):
        T += B[l][k]
    C.append(T)

D = []
for k in range(len(C)):
    if C[k] != "."*len(C[0]):
        D.append(C[k])

for k in range(len(D[0])):
    T = ""
    for l in range(len(D)):
        T += D[l][k]
    print(T)

Submission status: Accepted

Solution code:
input_s = str(input())
[n, k] = list(map(int, input_s.split(' ')))
m = []
for i in range(0, n):
    tmp = str(input())
    if tmp.find('#') > -1:
        m.append(tmp)
ta = []
for i in range(0, k):
    tmp = ''
    for j in m:
        tmp += j[i]

    ta.append(tmp)
tb = []
for i in ta:
    if i.find('#') > -1:
        tb.append(i)

result = []
for i in range(0, len(tb[0])):
    tmp = ''
    for j in tb:
        tmp += j[i]
    result.append(tmp)

for i in result:
    print(i)

Submission status: Accepted

Solution code:
nums = [int(num) for num in input().split()]
h = nums[0]
w = nums[1]
a = []
for i in range(h):
    a.append(input())
b = []
for i in range(h):
    hoge = True
    for j in range(w):
        if a[i][j] =="#":
            hoge = False

    if not hoge:
        b.append(a[i])

# print(b)
c = []

for i in range(w):
    hoge = True
    for j in range(len(b)):
        if b[j][i] == "#":
            hoge = False
    if not hoge:
        c.append(i)

ans = []
for i in range(len(b)):
    hoge =""
    for j in range(w):
        if j in c:
            hoge = hoge+b[i][j]
    ans.append(hoge)
        

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

Submission status: Accepted

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

def main():
    h, w = map(int, input().split())
    arry = [list(input()) for _ in range(h)]
    arry_new = []

    for i in range(h):
        if len(set(arry[i])) == 1 and arry[i][0] == '.':
            continue
        else:
            arry_new.append(arry[i])

    for j in range(len(arry_new[0])):
        flag = 1
        for k in range(len(arry_new)):
            if arry_new[k][j] == '.':
                flag *= 1
            else:
                flag *= 0
        if flag == 1:
            for l in range(len(arry_new)):
                arry_new[l][j] = ''
    for ans in arry_new:
        for i in ans:
            print(i, end='')
        print('')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H,W = (int(i) for i in input().split())

a = []
for i in range(H):
    tmpinput = input()
    tmp = []
    for j in range(W):
        tmp.append(tmpinput[j])
    a.append(tmp)

yoko = []
for i in range(H):
    shiro = True
    for j in range(W):
        if a[i][j] != ".":
            shiro = False
    if shiro:
        yoko.append(i)

tate = []
for i in range(W):
    shiro = True
    for j in range(H):
        if a[j][i] != ".":
            shiro = False
    if shiro:
        tate.append(i)

for i in range(H):
    tmp = ""
    for j in range(W):
        if (j not in tate) and (i not in yoko):
            tmp = tmp + a[i][j]
    if tmp != "":
        print(tmp)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
arr=[]
for i in range(n):
    s1=str(input())
    arr.append(s1)
row1=[]
col1=[]
for i in range(n):
    if(arr[i].count('.')<m):
        row1.append(i)
for j in range(m):
    for i in range(n):
        if(arr[i][j]!='.'):
            col1.append(j)
            break
for i in row1:
    s1=""
    for j in col1:
        s1+=arr[i][j]
    print(s1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

def solve():
    H, W = map(int, input().split())
    M = np.array([list(input())])
    for h in range(H-1):
        M = np.vstack((M,np.array([list(input())])))

    h = np.where(~(M == '.').all(axis=1))[0]
    v = np.where(~(M == '.').all(axis=0))[0]
    M = M[h,:][:,v]

    return '\n'.join([''.join([b for b in a]) for a in M])

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

b = []
for i in range(h):
    flag = 1
    for j in range(w):
        if a[i][j] == "#":
            flag = 0
    if not flag:
        b.append(a[i])

s = set()
for j in range(w):
    flag = 1
    for i in range(len(b)):
        if b[i][j] == "#":
            flag = 0
    if flag:
        s.add(j)

for i in b:
    c = ""
    for j in range(len(i)):
        if not j in s:
            c += i[j]
    print(c)

Submission status: Accepted

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

row = []
for i in range(H):
    line = input()
    if line.count(".") == W:
        continue
    row.append(line)

row_count = len(row)
ans = [[] for i in range(row_count)]
for i in range(W):
    tmp = []
    for j in range(row_count):
        tmp.append(row[j][i])
    if tmp.count(".") == row_count:
        continue
    else:
        for index, c in enumerate(tmp):
            ans[index].append(c)
for i in ans:
    print("".join(i))

Submission status: Accepted

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

for i in range(h-1,-1,-1):
    if not '#' in a[i]:
        del a[i]
h = len(a)
for j in range(w-1, -1, -1):
    res = True
    for i in range(h):
        if a[i][j] == '#':
            res = False
    if res:
        for i in range(h):
            del a[i][j]

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

Submission status: Accepted

Solution code:
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    h, w = na()
    a = sall()

    hs = []
    for i in range(h):
        if not [v for v in a[i] if v == '#']:
            hs.append(i)

    ws = []
    for i in range(w):
        if not [a[j][i] for j in range(h) if a[j][i] == '#']:
            ws.append(i)

    for i in range(h):
        p = False
        for j in range(w):
            if i in hs or j in ws:
                continue
            print(a[i][j], end='')
            p = True

        if p:
            print('')
            
main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
ans = []
n = h
for i in range(h):
  s = input()
  if("#" in s):
    ans.append(s)
  else:
    n -= 1
i = 0
j = w-1
while True:
  if(i > j):
    break
  flg = True
  for k in range(n):
    if(ans[k][i] == "#"):
      flg = False
      break
  if(flg):
    for k in range(n):
      ans[k] = ans[k][:i] + ans[k][i+1:]
    j -= 1
  else:
    i += 1
for i in ans:
  print(i)

Submission status: Accepted

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

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


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



for i in range(H):
	str=""
	for j in range(W):
		if A[i][j]!=0:
			str+=A[i][j]
	if len(str)!=0:
		print str

Submission status: Accepted

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

a = []

for i in range(h):
    s = input()
    f = 1
    for j in range(w):
        if s[j]=='#':
            f = 0
            break
    if f==0:    
        a.append(s)

out = []
for i in range(w):
    f =1
    for j in range(len(a)):
        if a[j][i] == '#':
            f = 0
            break
    if f == 1:
        out.insert(0, i)
        
        
for i in out:
    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:
H,W = map(int,input().split())
ma = [input() for i in range(H)]
ol = []
for i in range(len(ma)):
    if '#' in ma[i]:
        ol.append(ma[i])
f = True
deli = []
for i in range(len(ma[0])):
    f = True
    for i2 in range(len(ma)):
        if ma[i2][i] == '#':
           f = False
           break
    if f:
        deli.append(i)

for o in ol:
    s = ""
    for i in range(len(o)):
        if not i in deli:
            s += o[i]
    print(s)

Submission status: Accepted

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

b = []
for i in range(h):
    if a[i]!="."*w:
        b.append(a[i])

c = ["" for i in range(len(b))]

for i in range(w):
    for j in range(len(b)):
        if b[j][i] != ".":
            for k in range(len(b)):
                c[k] += b[k][i]
            break


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

Submission status: Accepted

Solution code:
h, w = [int(x) for x in input().split()]
m = []
for i in range(h):
    m.append(input())
n = []
for i, row in enumerate(m):
    if '#' in row:
        n.append(row)
flgs = []
for j in range(w):
    js = ''.join([row[j] for row in m])
    flgs.append('#' in js)
n = [''.join([item for i, item in enumerate(s) if flgs[i]]) for s in n]
for item in n:
    print(item)

Submission status: Accepted

Solution code:
H, W = list(map(int, input().split()))
X = []
h = 0
for i in range(H):
	a = input()
	if a == "." * W:
		pass
	else:
		X.append(list(a))
		h += 1

Y = []
w = 0
for i in range(W):
	x = ""
	for j in range(h):
		x += X[j][i]
	if x == "." * h:
		pass
	else:
		Y.append(list(x))
		w += 1

for i in range(h):
	n = ""
	for j in range(w):
		n += Y[j][i]

	print(n)

Submission status: Accepted

Solution code:

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

for i in range(h):
    ww = ["." for _ in range(w)]
    st = list(str(input()))
    if st != ww:
        hako.append(list(st))


hako2 = []
for i in range(w):
    one = []
    for onelist in hako:
        one.append(onelist[i])
    hako2.append(one)
    
hako3 = []
for _ in hako2:
    check = ["." for pp in range(len(_))]
    if _ != check:
        hako3.append(_)
        
hako4 = []

for i in range(len(hako3[0])):
    one = []
    for onelist in hako3:
        one.append(onelist[i])
    hako4.append(one)
    
for _ in hako4:
    strs = ""
    for char in _:
        strs += char
    print(strs)

Submission status: Accepted

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

def main():
    h, w = map(int, input().split())
    lines = [l for l in [input() for _ in range(h)] if l != '.' * w]
    lines2 = [''] * len(lines)
    for i in range(w):
        f = False
        for l in lines:
            if l[i] != '.':
                f = True
                break
        if f:
            for j, l in enumerate(lines):
                lines2[j] = lines2[j] + l[i]

    for l in lines2:
        print(l)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

d =[]
for i in range(len(c)):
    if '#' in c[i]:
        d.append(c[i])
e = [i for i in zip(*d)]

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

Submission status: Accepted

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

whiterow = [all(c == '.' for c in row) for row in grid]
whitecol = [all(row[i] == '.' for row in grid) for i in range(W)]

for r, row in enumerate(grid):
    if whiterow[r]: continue
    comp = [c for i, c in enumerate(row) if not whitecol[i]]
    print(''.join(comp))

Submission status: Accepted

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

m = []
l = [False for i in range(w)]

for i in range(h):
    s = input()
    flg = False
    if '#' in s:
        m.append(s)
    for j in range(w):
        if l[j]==False and s[j] == '#':
            l[j] = True
for i in m:
    for j in range(w):
        if l[j]:
            print(i[j],end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
array = [input() for x in range(h)]
res_array = []
for row in array:
    if len(row) != row.count("."):
        res_array.append(row)

array2 = [x for x in zip(*res_array)]
res_array2 = []
for row in array2:
    if len(row) != row.count("."):
        res_array2.append(row)

for i in [x for x in zip(*res_array2)]:
    print("".join(i))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
White = "."
Black = "#"

ans = []

for i in range(H):
    S = input()
    if(S.find(Black) == -1):
        H -= 1
    else:
        ans.append(list(S))

# print(ans)
i = 0
del_row = []
while(i < W):
    tmp = ""
    for j in range(H):
        tmp += ans[j][i]
    if(tmp.find(Black) == -1):
        del_row.append(i)

    i += 1

for i in reversed(del_row):
    for j in range(H):
        ans[j].pop(i)

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for _ in range(h):
    aa = list(input())
    a.append(aa)
b = []
for i in range(h):
    if "#" in a[i]:
       b.append(a[i])
tra = list(map(list, zip(*b)))
ans = []
for i in range(len(tra)):
    if "#" in tra[i]:
       ans.append(tra[i])
ans = list(map(list, zip(*ans)))
for j in ans:
    print("".join(j))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
delJ = []
for j in range(W):
    judge = True
    for i in range(H):
        if A[i][j] == "#":
            judge = False
            break
    if judge:
        delJ.append(j)

output = []
for i in range(H):
    if "#" in A[i]:
        B = ""
        for j in range(W):
            if j not in delJ:
                B += str(A[i][j])
        output.append(B)

for i in output:
    print(i)

Submission status: Accepted

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



for i in range(h):
  l = input()
  if '#' in l:
    a.append(l)
    
z = [False] * w

for i in range(w):
  for l in a:
    if l[i] == '#':
      z[i] = True
      break
    


for j, _ in enumerate(a):
  for i in range(w) :
    if z[i]:
      print(_[i], end='')
  if j == len(a) -1:
    break
  print('')

Submission status: Accepted

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

import numpy as np

h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]
buf = []
for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            buf.append(A[i])
            break
ret = []
for j in range(len(buf[0])):
    for i in range(len(buf)):
        if buf[i][j] == '#':
            ret.append([buf[k][j] for k in range(len(buf))])
            break
ans = np.array(ret).T
for line in ans:
    print(''.join(line))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
m = []
for i in range(H):
    r = list(input())
    if r == ['.'] * W:continue
    m.append(r)

k = []
for i in range(W):
    if [m[j][i] for j in range(len(m))] == ['.'] * len(m):
        k.append(i)

ans = []    
for r in m:
    t = []
    for i,l in enumerate(r):
        if  not i in k:
            t.append(l)
    ans.append(t)
for l in ans:
    print(''.join(l))

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:
from sys import stdin, stdout

input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    H, W = map(int, input().split())
    A = stdin.read().splitlines()

    def func(a):
        ret = []
        for s in a:
            if s.count('#'):
                ret.append(s)
        return ret

    ans = func(list(zip(*A)))
    ans = func(list(zip(*ans)))
    for s in ans:
        print(*s, sep='')

main()

Submission status: Accepted

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
M = [list(input()) for _ in range(h)]#[[x,x,x], [y,y,y], ..., [z,z,z]]

#wh = '.'
bk = '#'

for i in range(h):
    flg = True
    for j in range(w):
        if M[i][j] == bk:
            flg = False
            break
    if flg:
        for j in range(w):
            M[i][j] = ''

for j in range(w):
    flg = True
    for i in range(h):
        if M[i][j] == bk:
            flg = False
            break
    if flg:
        for i in range(h):
            M[i][j] = ''     

for i in range(h):
    res = ''
    for j in range(w):
        if M[i][j] != '':
            res += M[i][j]
    if res != '':
        print(res)

Submission status: Accepted

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

M = []

for i in range(H):
    M.append(raw_input())

M2 = []

for i in range(H):
    if '#' in M[i]:
        M2.append(M[i])

idx = []
for i in range(W):
    flag = True
    for j in range(len(M2)):
        if M2[j][i] == '#':
            flag = False

    if flag == False:
        idx.append(i)

M3 = []
for i in range(len(M2)):
    s = ''
    for j in range(W):
        if j in idx:
            s += M2[i][j]
    M3.append(s)

print '\n'.join(M3)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[list(input()) for _ in range(h)]
l=[i for i in l if i!=["."]*w]
h=len(l)
m=[]
for (i,j) in enumerate(zip(*l)):
  if j==tuple("." for _ in range(h)):
    m.extend([i])
for i in range(h):
  for j in range(w):
    if not j in m:
      print(l[i][j],end="")
  print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
b=[]
for i in range(h):
   n=input()
   if n.count(".")<w:a+=[n]
for i in range(w):
   if [I[i] for I in a].count(".")==len(a):
      b+=[i]
for i in range(len(a)):
   print("".join([a[i][I] for I in range(w) if I not in b]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
L = []
for h in range(H):
    s = input()
    if "#" in s:
        L.append(s)
        continue

S = []
for w in range(W):
    for l in range(len(L)):
        if L[l][w] == "#":
            break
    else:
        S.append(w)
    
for l in range(len(L)):
    s = ""
    for w in range(W):
        if not w in S:
            s += L[l][w]
    print(s)

Submission status: Accepted

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

for _ in range(H):
    a = input()
    A.append(a)

result = []
temp = []

for a in A:
    flag = True
    for s in a:
        if s != '.':
            flag = False
            break
    if not flag:
        temp.append(a)

idx = []

for i in range(W):
    flag = True
    for s in temp:
        if s[i] != '.':
            flag = False
            break
    if not flag:
        idx.append(i)

for s in temp:
    t = ''
    for i in idx:
        t += s[i]
    result.append(t)

print(*result, sep='\n')

Submission status: Accepted

Solution code:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

H, W =getMN()
all = []
for i in range(H):
    a = input()
    if "#" in a:
        all.append(a)

length = len(all[0])
raw = [0 for i in range(length)]

for r in all:
    for i in range(length):
        if r[i] == "#":
            raw[i] = 1

for r in all:
    for i in range(length):
        if raw[i] == 1:
            print(r[i],end="")
    print("")

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
a=[]
w=[False for _ in range(w)]
for _ in range(h):
    line=input()
    for i, ai in enumerate(line):
        if ai=='#':
            w[i]=True
    if '#' in line:
        a.append(line)

for ai in a:
    line=''
    for i, wi in enumerate(w):
        if wi:
            line+=ai[i]
    print(line)

Submission status: Accepted

Solution code:
import numpy as np


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

A = []

for h in range(H):
    a = list(input())
    if '#' in a:
        A.append(a)

A = np.rot90(np.array(A)).tolist()
B = []

for w in range(len(A)):
    if '#' in A[w]:
        B.append(A[w])


B = np.rot90(np.array(B), 3).tolist()

for b in B:
    print(str.join('', b))

Submission status: Accepted

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

#print(A)

H=[0 for i in range(h)]
W=[0 for i in range(w)]

for i in range(h):
    if A[i]=="."*w :
        H[i]=1
for i in range(w):
    co=0
    for j in range(h):
        if A[j][i]=="." :
            co+=1
    if co==h :
        W[i]=1


B=[]

for i in range(h):
    st=""
    if H[i]==0 :
        for j in range(w):
            if W[j]==0:
                st+=A[i][j]
        print(st)

Submission status: Accepted

Solution code:
h,w = list(map(int,input().split()))
h_ch = [0]*h
w_ch = [0]*w
inp = []
for i in range(h):
  inp.append(input())
  for j in range(w):
    h_ch[i] += 1 if inp[-1][j]=="#" else 0
    w_ch[j] += 1 if inp[-1][j]=="#" else 0
    
for i in range(h):
  if h_ch[i] > 0:
    out = ""
    for j in range(w):
      if w_ch[j] > 0:
        out += inp[i][j]
    print(out)