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=int(input())
h,w=map(int,input().split())
#l=list(map(int,input().split()))
l=[list(input()) for i in range(h)]

# まずは行について確認する
row_compare=['.' for i in range(w)]
save_rows=[]
for row in range(h):
    if not l[row]==row_compare:
        save_rows.append(row)

newl=[l[row] for row in save_rows]

h=len(newl)
#次は列
save_col=[]
col_compare=["." for i in range(h)]
for col in range(w):
    temp=[]
    for row in range(h):
        temp.append(newl[row][col])
    if not temp==col_compare:
        save_col.append(col)

ansl=[]
for row in range(h):
    temp=[]
    for col in range(w):
        if col in save_col:
            temp.append(newl[row][col])
    ansl.append(temp)

for row in ansl:
    print(*row,sep="")

Submission status: Accepted

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

lis = []
for _ in range(h):
    tmp = input()
    lis.append(list(tmp))
    
flag = 0
delg = []
for i in range(h):
    for j in range(w):
        if lis[i][j] == "#":
            flag = 1
            break
        else:
            flag = 0
    
    if flag == 0:
        delg.append(i)
        
nlis = []

if delg != False:    
    for k in range(h):
        if k not in delg:
            nlis.append(lis[k])
            
h = h - len(delg)

flg = 0
delr = []

for k in range(w):
    for i in range(h):
        if nlis[i][k] == "#":
            flg = 1
            break
        else:
            flg = 0
    
    if flg == 0:
        delr.append(k)
        
delr = list(reversed(delr))


if delr != False:
    for i in range(h):
        for j in delr:
            nlis[i].pop(j)

for l in nlis:
    print("".join(l))

Submission status: Accepted

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

dh = []
for l in A:
    if l[0] == '.' and len(set(l)) == 1:
        continue
    dh.append(l)

wj = []
for j in range(w):
    for i in range(len(dh)):
        if dh[i][j] == '#':
            wj.append(j)
            break

ans = ['' for _ in range(len(dh))]
for i in range(len(ans)):
    for j in wj:
        ans[i] += dh[i][j]
print('\n'.join(ans))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
#print(a)
A=[]
for i in range(h):
    if "#" in a[i]:
        A.append(a[i])
#print(A)
l=[]
for i in range(len(A[0])):
    x=0
    for j in range(len(A)):
        if A[j][i]==".":
            x+=1
    if x==len(A):
        l.append(i)
#print(l)
for i in range(len(A)):
    ans=""
    for j in range(len(A[0])):
        if j in l:
            continue
        else:
            ans+=A[i][j]
    print(ans)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[[""]*W for i in range(H)]
for i in range(H):
  a[i]=list(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]==True:
    for j in range(W):
      if col[j]==True:
        print(a[i][j],end="")
    print("")

Submission status: Accepted

Solution code:
import sys
import numpy as np

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def kk(al):
	for i in range(len(al)-1, -1, -1):
		if list(al[i]) == ['.']*len(al[i]):
			al = np.delete(al, i, 0)
	return al

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	al=[]
	for _ in range(h):
		s=list(input())
		al.append(s)
	al = np.array(al)
	al = kk(al)
	al = kk(al.T)
	al=al.T
	for v in al:
		print(''.join(v))
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def cut(a):
    w = len(a[0])
    l = []
    for row in a:
        if row != ['.']*w:
            l.append(row)
    return l

def main():
    H, W = mi()
    a = [list(input()) for _ in range(H)]
    a = cut(a)
    a = cut([list(i) for i in zip(*a)])
    [print(''.join(list(i))) for i in zip(*a)]

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
array = []
for _ in range(h):
    temp = input()
    if temp.count(".")==w:
        h-=1
        continue
    array.append(temp)

skip = [i for i in range(w)]

for j in range(w):
    flag=0
    for i in range(h):
        if array[i][j]=="#":
            flag=1
            break
    if flag==0:
        skip.remove(j)

for i in range(h):
    for j in skip:
        print(array[i][j], end="")
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
m=[]
for _ in range(h):
    l=input()
    if '#' in l:
        m.append(l)
m=list(zip(*m))
n=[]
for i in m:
    if '#' in i:
        n.append(i)
n=list(zip(*n))
for i in n:
    for j in i:
        print(j,end='')
    print('')

Submission status: Accepted

Solution code:
def resolve():
    H, W = [int(i) for i in input().split()]
    A = [input() for _ in range(H)]
    skipC = [False for _ in range(W)]
    skipR = [False for _ in range(H)]
    for i in range(H):
        if A[i] == "".join(["." for _ in range(W)]):
            skipR[i] = True
    for i in range(W):
        for j in range(H):
            if A[j][i] != ".":
                break
        else:
            skipC[i] = True

    for i in range(H):
        if skipR[i]:
            continue
        for j in range(W):
            if skipC[j]:
                continue
            print(A[i][j], end="")
        print("")


resolve()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
temp = []
for i in range(H):
    if a[i] == ('.' * W):
        pass
    else:
        temp.append(a[i])
a = temp
temp = []
for i in range(W):
    flg = True
    for j in range(len(a)):
        if not a[j][i] == '.':
            flg = False
        if not flg:
            break
    else:
        temp.append(i)

for i in range(len(a)):
    for j in range(W):
        if j in temp:
            pass
        else:
            print(a[i][j], end='')
    print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [0]*h
for i in range(h):
    a[i] = list(input())
b = []
for i in range(h):
    if a[i] == ["."]*w:
        pass
    else:
        b.append(a[i])
c = [[0 for j in range(w)] for i in range(h)]
for i in range(w):
    sw = 1
    for j in range(len(b)):
        if  b[j][i] == "#":
            sw = 0
            break
    if sw == 0:
        for j in range(len(b)):
            c[j][i] = b[j][i]
for i in range(len(c)):
    for j in range(len(c[0])):
        if c[i][j] != 0:
            print(c[i][j],end="")
    print("")

Submission status: Accepted

Solution code:
import numpy as np

# H, W = 4, 4
# ARR = [
#     ["#", "#", ".", "#"],
#     [".", ".", ".", "."],
#     ["#", "#", ".", "#"],
#     [".", "#", ".", "#"],
# ]



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

for i in range(H):
    ARR.append(list(input()))


def calculate(h, w, arr):
    arr = np.array(arr)
    arr = np.where(arr == ".", 0, 1)
    s = np.sum(arr, axis=1)

    p = s > 0
    m = arr[p]


    t = np.sum(m, axis=0)

    o = t > 0

    res = m[:, o]

    res = np.where(res==1,"#",".")

    for re in res:
        print("".join(re))



calculate(H, W, ARR)

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:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


import numpy as np


# In[33]:


H,W = map(int, input().split())
a = []
for _ in range(H):
    row = input()
    a.append([1 if row[i] == "#" else 0 for i in range(W)])


# In[36]:


a_array = np.array(a)
col_flag = True
row_flag = True
# print(a_array)
while col_flag:
    for col in range(len(a_array)):
        if sum(a_array[col]) == 0:
            a_array = np.delete(a_array, col, 0)
#             print(a_array)
            break
    else:
        col_flag = False
while row_flag:
    for row in range(len(a_array[0])):
        if sum(a_array[:,row]) == 0:
            a_array = np.delete(a_array, row, 1)
#             print(a_array)
            break
    else:
        row_flag = False
for i in range(len(a_array)):
    tmp = ["#" if x == 1 else "." for x in a_array[i]]
    print("".join(tmp))


# In[ ]:

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    A = [0]*H
    for i in range(H):
       A[i] = [a for a in input()]
    # print(A)
    B = []
    for i in range(H):
        found = False
        for j in range(W):
            if A[i][j] == '#':
                found = True
                break
        if found:
            B.append(A[i])
    # print(B)
    h = len(B)
    C = [[] for i in range(h)]
    for j in range(W):
        found = False
        for i in range(h):
            if B[i][j] == '#':
                found = True
                break
        if found:
            for i in range(h):
                C[i].append(B[i][j])
    for i in range(h):
        print(''.join(C[i]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    h,w = readInt()
    a = [input() for i in range(h)]
    H = []
    W = []
    for i in range(h):
        f = True
        for j in range(w):
            if a[i][j]=='#':
                f = False
                break
        if f:
            H.append(i)
    for i in range(w):
        f = True
        for j in range(h):
            if a[j][i]=='#':
                f = False
                break
        if f:
            W.append(i)
    ans = []
    for i in range(h):
        if i in H:
            continue
        x = []
        for j in range(w):
            if j in W:
                continue
            x.append(a[i][j])
        ans.append(x)
    for i in range(len(ans)):
        print(''.join(ans[i]))
    return

if __name__=='__main__':
    main()

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)

b = [[a[x][y] for x in range(len(a))] for y in range(w)]
a = []
for x in b:
    if '#' in x:
        a.append(x)


for i in range(len(a[0])):
    for x in a:
        print(x[i], end='')
    print()

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
"""
入力はスペースなしだった
文字列としてリストの行にぶち込む必要あり
icon=list()
for i in range(h):
    icon.append(list(input().split()))

"""
icon=[''] * h
for i in range(h):
    icon[i]=input()


row=[False]*h
col=[False]*w

for i in range(h):
    for j in range(w):
        if icon[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(icon[i][j],end='')
        print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
temp = []
for _ in range(h):
  l = list(input())
  if l.count('#')!=0:
    temp.append(l)
h = len(temp)
#print(temp)
cols = []
for j in range(w):
  valid = False
  for i in range(h):
    if temp[i][j]=='#':
      valid = True
  if not valid:
    cols.append(j)
for i in range(h):
  for j in range(w):
    if j not in cols:
    	print(temp[i][j],end='')
  print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for i in range(h)]
yoko=[]
tate=[]
for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      tate.append(i)
      break
for i in range(w):
  for j in range(h):
    if a[j][i]=="#":
      yoko.append(i)
      break
for i in tate:
  l=[a[i][j] for j in yoko]
  l="".join(l)
  print(l)

Submission status: Accepted

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

a = np.array(a).reshape(h, w)
a = [i for i in a if "#" in i]

a = np.array(a).T
a = [i for i in a if "#" in i]

a = np.array(a).T
for i in a:
    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(2):
    a = [j for j in a if "#" in j]
    a = list(map(list, (zip(*a))))
for i in a:
    print("".join(i))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
k = []
h_remove = []
w_remove = []
for i in range(h):
    ls = input()
    if ls.count(".") == w:
        h_remove.append(i)
    k.append(ls)
for i in range(w):
    now = ""
    for j in range(h):
        now += k[j][i]
    if now.count(".") == h:
        w_remove.append(i)
h_remove = set(h_remove)
w_remove = set(w_remove)
for i in range(h):
    ans = ""
    if i in  h_remove:
        continue
    else:
        for j in range(w):
            if j in w_remove:
                continue
            else:
                ans += k[i][j]
        print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    A = list(list(input()) for _ in range(H))

    res = []
    remove = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                res.append(A[h])
                break
        else:
            remove += 1
    H -= remove

    res2 = [[] for _ in range(H)]
    for w in range(W):
        for h in range(H):
            if res[h][w] == "#":
                for i in range(H):
                    res2[i].append(res[i][w])
                break

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# 20200610_yorukatsu_e.py
H,W = map(int,input().split())
glid = [list(input()) for _ in range(H)]

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

        print()

Submission status: Accepted

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

for i in range(2):
    grid = [col for col in grid if '#' in col ]
    grid = list(map(list, (zip(*grid))))

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

Submission status: Accepted

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

s = []
for i in range(h):
    tmp = list(input())
    if "#" in tmp:
        s.append(tmp)

c = [0]*w
for i in s:
    for j in range(w):
        if i[j] == "#":
            c[j] = 1

for i in s:
    for j in range(w):
        ans = i[j] if c[j] == 1 else ""
        print(ans, end="")
    print("")

Submission status: Accepted

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

non_h = []
for i in range(h):
  set_l = list(set(l[i]))
  if len(set_l) == 1 and set_l[0] == '.':
    non_h.append(i)
for i in range(len(non_h)):
  l.pop(non_h[i] - i)

non_w = []
for j in range(w):
  a = []
  for i in range(len(l)):
    a.append(l[i][j])
  b = list(set(a))
  if len(b) == 1 and b[0] == '.':
    non_w.append(j)

new_l = []
for i in range(len(l)):
  new = []
  for j in range(len(l[i])):
    if not j in non_w:
      new.append(l[i][j])
  new_l.append(new)

for e in new_l:
  for i in range(len(e)):
    print(e[i], end='')
  print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = [[] for _ in range(h)]
for i in range(h):
    A[i] = list(input())
flag = True
while flag:
    flag = False
    for i, a in enumerate(A):
        if not '#' in a:
            flag = True
            A.pop(i)
            break
    for j in range(len(A[0])):
        a = []
        for i in range(len(A)):
            a.append(A[i][j])
        if not '#' in a:
            flag = True
            for i, a in enumerate(A):
                A[i].pop(j)
            break
for a in A:
    temp = ''.join(a)
    print(temp)

Submission status: Accepted

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

a = [list(input()) for i in range(H)]
cnt = 0
i = 0
while i < len(a):
    for j in range(W):
        if a[i][j] not in '#':
            cnt += 1
    if cnt == W:
        a.remove(a[i])
        i -= 1
        H -= 1
    cnt = 0
    i += 1
i = 0
cnt = 1
while i < W:
    if a[0][i] == '.':
        for j in range(1,H):
            if a[j][i] == '.':
                cnt += 1
        if cnt == H:
            for j in range(H):
                a[j].pop(i)
            W -= 1
            i -= 1
    cnt = 1
    i += 1
[print(''.join(a[i])) for i in range(H)]

Submission status: Accepted

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

l = [0]*w
for i in range(h) :
    for j in range(w) :
        if A[i][j] == '.' :
            l[j]+= 1

for i in range(w) :
    if l[i] == h :
        for j in range(h) :
            A[j][i] = 0

for i in range(h) :
    aa = [i for i in A[i] if i != 0]
    ans = ''.join(aa)
    print(ans)

Submission status: Accepted

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

clm = [True] * H
for hi in range(H):
  ai = a[hi]
  for c in ai:
    if c == '#':
      clm[hi] = False
      break
      
row = [True] * W
for wi in range(W):
  for ci in range(H):
    if a[ci][wi] == '#':
      row[wi] = False
      break
      
for hi in range(H):
  if clm[hi] == True:
    continue
  ans = ''
  ai = a[hi]
  for wi in range(W):
    if row[wi] == True:
      continue
    ans += ai[wi]
  print(ans)

Submission status: Accepted

Solution code:
n, m=  map(int, input().split())
grid = []
for i in range(n):
    grid.append(list(input()))
i = 0
while i < n:
    replace = True
    for j in range(m):
        if grid[i][j] != '.':
            replace = False
            break
    if replace:
        grid.pop(i)
        n -= 1
    else:
        i+=1
i = 0
while i < m:
    replace = True
    for j in range(n):
        if grid[j][i] != '.':
            replace = False
            break
    if replace:
        for x in range(n):
            grid[x].pop(i)
        m-=1
    else:
        i+=1
for i in range(n):
    for j in range(m):
        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=map(int,input().split())
a=[]
for _ in range(H):
  a.append(list(input()))

for i in range(H):
  is_in_black=False
  for j in range(W):
    if a[i][j]=='#':
      is_in_black=True
      break
  if is_in_black == False:
    for j in range(W):
      a[i][j]=0
  pass

for j in range(W):
  is_in_black=False
  for i in range(H):
    if a[i][j]=='#':
      is_in_black=True
      break
  if is_in_black == False:
    for i in range(H):
      a[i][j]=0
  pass

# print ans
for i in range(H):
  ans = ''
  for j in range(W):
    if a[i][j]!=0:
      ans+=a[i][j]
  if len(ans)!=0:
    print(ans)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
ls = [list(input()) for _ in range(h)]
num = []
di = [0]*w
for i in range(h):
    if "#" not in ls[i]:
        num.append(i)
    for j in range(w):
        if ls[i][j] == "#":
            di[j] += 1
num = sorted(num,reverse=True)
for k in range(h-1,-1,-1):
    if k in num:
        ls.pop(k)
        continue
    for l in range(w-1,-1,-1):
        if di[l] == 0:
            ls[k] = ls[k][:l] + ls[k][l+1:]
for p in range(h-len(num)):
    print("".join(ls[p]))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

white_y = [0] * H
white_x = [1] * W

masu = []
for i in range(H):
    yoko = list(readline().decode("utf-8"))
    if not "#" in yoko:
        white_y[i] = 1
    for j, x in enumerate(yoko):
        if x == "#":
            white_x[j] = 0
    masu.append(yoko)

# print(white_y)
# print(white_x)

for i in range(H):
    if white_y[i] == 1:
        continue
    s = ""
    for j in range(W):
        if white_x[j] == 1:
            continue
        s += masu[i][j]
    print(s)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
ls = [list(input()) for _ in range(h)]
num = []
di = [0]*w
for i in range(h):
    if "#" not in ls[i]:
        num.append(i)
    for j in range(w):
        if ls[i][j] == "#":
            di[j] += 1
num = sorted(num,reverse=True)
for k in range(h-1,-1,-1):
    if k in num:
        ls.pop(k)
        continue
    for l in range(w-1,-1,-1):
        if di[l] == 0:
            if l != 0 and l != w-1:
                ls[k] = ls[k][:l] + ls[k][l+1:]
            elif l == 0:
                ls[k] = ls[k][1:]
            else:
                ls[k] = ls[k][:w-1]
for p in range(h-len(num)):
    print("".join(ls[p]))

Submission status: Accepted

Solution code:
# B - Grid Compression

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

h = [0] * H
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            h[i] = 1
            continue

w = [0] * W
for j in range(W):
    for i in range(H):
        if A[i][j] == '#':
            w[j] = 1
            continue

for i in range(H):
    ans = ''
    if h[i] == 0:
        continue
    for j in range(W):
        if w[j] == 0:
            continue
        else:
            ans += A[i][j]
    print(ans)

Submission status: Accepted

Solution code:
# B - Grid Compression

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

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

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

for i in range(H):
    ans = ''
    if h[i] == 0:
        continue
    for j in range(W):
        if w[j] == 0:
            continue
        else:
            ans += A[i][j]
    print(ans)

Submission status: Accepted

Solution code:
# B - Grid Compression

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

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

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

for i in range(H):
    ans = ''
    if h[i] == 0:
        continue
    for j in range(W):
        if w[j] == 0:
            continue
        else:
            ans += A[i][j]
    print(ans)

Submission status: Accepted

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

ans=[]
for i in range(h):
  if s[i]!='.'*w:
    ans.append(s[i])

n=len(ans)
a=['' for i in range(n)]

for i in range(w):
  sm=''
  cnt=0
  for j in range(n):
    sm+=ans[j][i]
    if ans[j][i]!='.':
      cnt+=1
  if cnt!=0:
    for k in range(n):
      a[k]+=ans[k][i]
m=len(a)
for i in range(m):
  print(a[i])

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
while "."*w in a:
	a.remove("."*w)
lena = len(a)
b = ["".join([a[i][j] for i in range(lena)]) for j in range(w)]
while "."*lena in b:
	b.remove("."*lena)
c = [[b[i][j] for i in range(len(b))] for j in range(len(a))]
for i in c:
	print("".join(i))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    omit = set([])
    for j in range(W):
        white = True
        for i in range(H):
            if A[i][j] == '#':
                white = False
                break
        if white: omit.add(j)
    for i in range(H):
        white = True
        for j in range(W):
            if A[i][j] == "#":
                white = False
                break
        if white: continue
        ans = ""
        for j in range(W):
            if j not in omit:
                ans += A[i][j]
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
a = np.zeros(shape=(H, W), dtype=bool)
for i in range(H):
  a[i] = [s == "." for s in input()]

y = [True] * H
for i in range(H):
  if all(a[i,:]):
    y[i] = False

x = [True] * W
for i in range(W):
  if all(a[:,i]):
    x[i] = False

ans = []
for i in range(H):
  if not y[i]:
    continue
  s = ""
  for j in range(W):
    if not x[j]:
      continue
    s = "".join([s, "." if a[i,j] else "#"])
  ans.append(s)

print(*ans, sep="\n")

Submission status: Accepted

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

a = [0]*h
b = []
for i in range(0,h):
  a[i] = input()
  
i = 0
tmp = 0
for i in range(0,h):
  if a[i].count(".") == w:
    tmp += 1
  else:
    b.append(a[i])
    
#print(b) 

b = list(zip(*b))
#print(b)
c = []
h = h - tmp
#print(h)
tmp = []

for i in range(0,w):
  if b[i].count(".") == h:
    continue
  else:
    c.append(b[i])
    
#print(c)

c = list(zip(*c))

for i in c:
  i = ''.join(i)
  print(i)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
M=[list(input()) for i in range(H)]
for i in range(H):
    if '#'in M[i]:
        s=[]
        for x in range(W):
            t=[M[y][x] for y in range(H)]
            if '#'in t: s.append(M[i][x])
        print(''.join(s))

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
arr = np.array(a)

for i in reversed(range(arr.shape[0])):
    if not '#' in arr[i]:
        arr = np.delete(arr, i, 0)
        
for i in reversed(range(arr.shape[1])):
    if not '#' in arr[:,i]:
        arr = np.delete(arr, i, 1)

a = arr.tolist()

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

Submission status: Accepted

Solution code:
height, width = map(int, input().split())
lis = [[0 for i in range(width)] for i in range(height)]
for i in range(height):
    lis[i] = input()

blank_rows = []
for row in range(height):
    if not "#" in lis[row]:
        blank_rows.append(row)

blank_cols = []
for col in range(width):
    flag = 1
    for row in range(height):
        if "#" == lis[row][col]:
            flag = 0
            break
    if flag:
        blank_cols.append(col)

for row in range(height):
    out = ""
    if not row in blank_rows:
        for col in range(width):
            if not col in blank_cols:
                out += lis[row][col]
    if not out == "":
	    print(out)

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


r, c = invr()

a = []
for _ in range(r):
    a.append(instr())

for i in range(r):
    h = a[i].count("#")
    if h == 0:
        for j in range(c):
            a[i][j] = "-1"
for i in range(c):
    count = 0
    for j in range(r):
        if a[j][i] == "#":
            count += 1
    if count == 0:
        for j in range(r):
            a[j][i] = "-1"

for i in range(r):
    f = 0
    for j in range(c):
        if a[i][j] != "-1":
            f = 1
            print(a[i][j], end="")
    if f:
        print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
grid = []
for i in range(H):
    row = list(input())
    grid.append(row)
row_flags = [1] * H
col_flags = [1] * W

for i in range(H):
    t = grid[i][0]
    if t != ".":
        continue
    for j in range(1, W):
        if grid[i][j] != t:
            break
    else:
        row_flags[i] = 0
for j in range(W):
    t = grid[0][j]
    if t != ".":
        continue
    for i in range(1, H):
        if grid[i][j] != t:
            break
    else:
        col_flags[j] = 0

for i in range(H):
    if not row_flags[i]:
        continue
    for j in range(W):
        if not col_flags[j]:
            continue
        print(grid[i][j], end="")
    print()