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:
# -*- coding: utf-8 -*-

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

delete = []
for i in range(h):
    if not("#" in a[i]):
        delete.append(i)

diff = 0
for i in range(len(delete)):
    del a[delete[i] - diff]
    diff += 1

bucket = [0] * len(a[0])
for i in range(len(a)):
    for j in range(len(a[0])):
        if a[i][j] == "#":
            bucket[j] += 1

delete = []
for i in range(len(bucket)):
    if bucket[i] == 0:
        delete.append(i)

diff = 0
for i in range(len(delete)):
    for j in range(len(a)):
        del a[j][delete[i] - diff]
    diff += 1

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for i in range(H)]
res = [0 for i in range(W)]
for i in range(W):
  for j in range(H):
    if a[j][i] != ".":
      break
    res[i] += 1
for i in range(H):
  if a[i][0:].count("#") >0:
    for j in range(W):
      if res[j] != H:
        print(a[i][j],end="")
    print("")

Submission status: Accepted

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

while ('.' * w in A):
  A.remove('.' * w)

B = [''.join(col) for col in zip(*A)]

while ('.' * len(A) in B):
  B.remove('.' * len(A))


A = [''.join(col) for col in zip(*B)]

for a in A:
  print(''.join(a))

Submission status: Accepted

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

for h in range(H):
    if list[h] == '.'*W:
        del_H.append(h)

for w in range(W):
    list_C = []
    for h in range(H):
        list_C.append(list[h][w])
        if ''.join(list_C) == '.'*H:
            del_W.append(w)

list_new = []

for h in range(H):
    list_join = []
    if h in del_H:
        continue
    for w in range(W):
        if w in del_W:
            continue
        list_join.append(list[h][w])
    join_w = ''.join(list_join)
    list_new.append(join_w)

for i in list_new:
    print(i)

Submission status: Accepted

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

#solve
has_black = [0 for _ in range(H)]
for i in range(H):
    if "#" in a[i]:
        has_black[i] = 1
new_a_1 = []
for i in range(H):
    if has_black[i] == 1:
        new_a_1.append(a[i])

for i in range(W):
    for j in range(len(new_a_1)):
        if new_a_1[j][i] == "#":
            break
    else:
        for j in range(len(new_a_1)):
            new_a_1[j][i] = ""

for string in new_a_1:
    print("".join(string))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
ans = []
ans2 = []
for i in range(H):
    a.append(input())
for i in range(H):
    if all(x == '.' for x in a[i]):
      continue
    else:
        ans.append(a[i])

ans = list(map(list, zip(*ans)))

for i in range(W):
    if all(x == '.' for x in ans[i]):
      continue
    else:
        ans2.append(ans[i])
        
ans2 = list(map(list, zip(*ans2)))    

for i in range(len(ans2)):
    for j in range(1, len(ans2[0])):
        ans2[i][0] += ans2[i][j]
    print(ans2[i][0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import itertools
import collections
from queue import Queue
import functools
import math
import numpy as np

INF = 10**9


def main():
    H, W = [int(x) for x in input().split()]
    a = [input() for _ in range(H)]

    # print(a)
    ans = []
    for item in a:
        flag = False
        for v in item:
            if v == "#":
                flag = True
        if flag == True:
            ans.append(item)
    a = ans
    H = len(a)

    # 列
    ans = [[] for x in range(H)]
    for i in range(W):
        flag = False
        for item in a:
            if item[i] == "#":
                flag = True
        if flag == True:
            for j in range(H):
                ans[j].append(a[j][i])
    for item in ans:
        print(*item, sep="")
    pass


if __name__ == '__main__':
    main()

Submission status: Accepted

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

while "." * w in a:
  a.remove("." * w)
hh = len(a)
  
a = ["".join(h_line) for h_line in zip(*a)]
while "." * hh in a:
  a.remove("." * hh)
    
for line in zip(*a):
  print("".join(line))

Submission status: Accepted

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

ls = [input() for _ in range(h)]
drops_h = []
drops_w = []

for i in range(h):
    if all([ls[i][j] == "." for j in range(w)]):
        drops_h.append(i)
    
for i in range(w):
    if all([ls[j][i] == "." for j in range(h)]):
        drops_w.append(i)

for i in range(h):
    if i in drops_h:
        continue
    else:
        for j in range(w):
            if j in drops_w:
                continue
            else:
                print(ls[i][j], end = "")
        
        print()

Submission status: Accepted

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

chs = {h for h in range(H) if all(a == '.' for a in ah[h])}
cws = {w for w in range(W) if all(a[w] == '.' for a in ah)}

for h in range(H):
    if h not in chs:
        print(''.join(ah[h][w] for w in range(W) if w not in cws))

Submission status: Accepted

Solution code:
def allb(S):
    for i in S:
        if not i == '.':
            return False
    return True

H,W = list(map(int,input().split()))
masu = [input() for i in range(H)]
masu = [i for i in masu if not allb(i)]
new = [[] for i in range(W)]
for i in range(len(masu)):
    for j in range(len(masu[0])):
        new[j].append(masu[i][j])
new = [i for i in new if not allb(i)]
masu = [[] for i in range(W)]
for i in range(len(new)):
    for j in range(len(new[0])):
        masu[j].append(new[i][j])
for i in masu:
    if i:
        for j in i:
            print(j,end="")
        print()

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
ans = []
for i in range(H):
    if set(a[i]) != set("."):
        ans.append(a[i])
a = list(np.array(ans).T)
ans = []
for i in range(len(a)):
    if set(a[i]) != set("."):
        ans.append(a[i])
ans = list(np.array(ans).T)
for res in ans:
    print("".join(res))

Submission status: Accepted

Solution code:
H,W = [int(x) for x in input().split()]
a = [0]*H
ng_h = []
ng_w = []
for i in range(H):
    a[i] = [1 if x == '#' else 0 for x in input()]

for i in range(H):
    if(sum(a[i]) == 0):
        ng_h.append(i)
for j in range(W):
    sumw = 0
    for i in range(H):
        sumw += a[i][j]
    if(sumw == 0):
        ng_w.append(j)


for i in range(H):
    flag = False
    for j in range(W):
        if((not i in ng_h) and (not j in ng_w)):
            flag = True
            print('#' if a[i][j] == 1 else '.',end = '')
    if(flag):
        print()

Submission status: Accepted

Solution code:
H,W = list(map(int,input().split()))
a = [list(input()) for i in range(H)]
H_new = H
b = []
for h in range(H):
	judge = True
	for w in range(W):
		#print(h,w)
		if a[h][w] != ".":
			judge = False
	if judge:
		H_new -= 1
	else:
		b.append(a[h])
c = []
W_new = W
for w in range(W):
	judge = True
	for h in range(H_new):
		if b[h][w] != ".":
			judge = False
	if judge:
		W_new -= 1
	else:
		b_new = []
		for h in range(H_new):
			b_new.append(b[h][w])
		c.append(b_new)

for h in range(H_new):
	for w in range(W_new):
		print(c[w][h],end = "")
	print("")

Submission status: Accepted

Solution code:
import numpy as np

data = input().split()

h = int(data[0])
w = int(data[1])

count = 0
# creating math
i = 0
math = []
while i < h:
    x = input()
    x = list(x)
    math.append(x)
    i += 1
math = np.array(math).reshape(h,w)


# row check

i = 0 # row
j = 0 # colum
while i < h:
    while j < w:
        if math[i][j] == ".":
            
            j += 1
            if j == w:
                math = np.delete(math,i,0)
                h = h-1
                i -=1
                
                
                
        else:
            break
    j = 0
    i += 1
i = 0
j = 0

# colum check

while j < w:
    while i < h:
        if math[i][j] == ".":
            
            i += 1
            if i == h:
                math = np.delete(math,j,1)
                w = w-1
                j -= 1
                
                
        else:
            break
    i = 0
    j += 1
i = 0
j = 0
while i < h:
    while j < w:
        print(*math[i][j],end = "")
        j += 1
    i += 1
    j = 0
    print()

Submission status: Accepted

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

for i in range(h):
    if not a[i].count('#'):
        b[i] = 0

for i in range(w):
    flag = True
    for j in range(h):
        if a[j][i] == '#':
            flag = False
    if flag:
        b[i + h] = 0

for i in range(h):
    for j in range(w):
        if b[i] and b[j + h]:
            print(a[i][j], end = '')
    if b[i]:
        print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for i in range(h)]
removeh = []
removew = []
for i in range(h):
    if not "#" in a[i]:
        removeh.append(i)
for i in range(w):
    flag = 0
    for j in range(h):
        if a[j][i] == "#":
            flag = 1
            break
    if flag == 0:
        removew.append(i)

for i in range(h):
    if removeh.count(i) == 0:
        buf = ""
        for j in list(set(range(w)) - set(removew)):
            buf += a[i][j]
        print(buf)

Submission status: Accepted

Solution code:
import numpy as np

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

a = []
array = np.zeros((H,W))
for i in range(H):
    tmp = [i for i in input().split()]
    for j in range(W):
        if(tmp[0][j]=="."):
            array[i,j]=0
        else:
            array[i,j]=1

#---------------
survive_h = []
survive_w = []

for i in range(H):
    if(np.sum(array[i])!=0):
        survive_h.append(i)

for i in range(W):
    if(np.sum(array[:, i])!=0):
        survive_w.append(i)

deleted_array = array[survive_h][:,survive_w]

for i in range(len(deleted_array)):
    s=""
    for j in range(len(deleted_array[0])):
        if(deleted_array[i][j]==1):
            s += "#"
        else:
            s += "."
    print(s)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n):
  l1=list(input())
  b=True
  for j in l1:
    if j=="#":
      b=False
  if b==False:
    l.append(l1)
for i in range(m):
  b=True
  for j in range(len(l)):
    if l[j][m-1-i]=="#":
      b=False
  if b:
    for j in range(len(l)):
      del l[j][m-1-i]
for i in range(len(l)):
  print("".join(l[i]))

Submission status: Accepted

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

grid = []

for i in range(H):
    line = input()
    if line == '.'*W:
        continue
    grid.append(list(line))

for j in range(W):
    line = ''
    for i in range(len(grid)):
        line += grid[i][j]
    if line == '.'*len(grid):
        for i in range(len(grid)):
            grid[i][j] = '0'

for i in range(len(grid)):
    line = grid[i]
    line = ''.join(line).replace('0','')
    print(line)

Submission status: Accepted

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

tmp = a.copy()
for i,row in enumerate(tmp[::-1],1):
    for c in row:
        if c == "#":
            break
    else:
        a.pop(H-i)
tmp = len(a)
for i in range(W-1,-1,-1):
    for j in range(tmp):
        if a[j][i] == "#":
            break
    else:
        for j in range(tmp):
            a[j].pop(i)

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

Submission status: Accepted

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

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

row_deleted = [False for i in range(H)]
col_deleted = [False for i in range(W)]

for i in range(H):
    all_white = True
    for e in a[i]:
        if e != ".":
            all_white = False
    
    if all_white:
        row_deleted[i] = True
    
for i in range(W):
    all_white = True
    for j in range(H):
        if not row_deleted[j] and a[j][i] != ".":
            all_white = False
    
    if all_white:
        col_deleted[i] = True
        
for i in range(H):
    if row_deleted[i]:
        continue
    for j in range(W):
        if col_deleted[j]:
            continue
        print(a[i][j], end = '')
    print("")

Submission status: Accepted

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

rs = []
for a in a_s:
    if "#" in a:
        rs.append(a)
ans = ["" for _ in rs]
for i in range(W):
    comp = True
    for r in rs:
        if r[i] == "#":
            comp = False
    if not comp:
        for j, r in enumerate(rs):
            ans[j] += r[i]

print("\n".join(ans))

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
a = np.array([list(input()) for _ in range(H)])
row = np.all(a == '.', axis=0)
col = np.all(a == '.', axis=1)
for i in range(H):
    if col[i]:
        continue
    for j in range(W):
        if row[j]:
            continue
        print(a[i][j], end='')
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
h1=[0 for i in range(h)]
w1=[0 for i in range(w)]
m=[]
for i in range(h):
  a=input()
  m+=[a]
  if not "#" in a:
    h1[i]=1
    
for i in range(w):
  k=1
  for j in range(len(m)):
    if m[j][i]=="#":
      k=0
      break
  if k==1:
    w1[i]=1
    
for i in range(h):
  if h1[i]==1:
    continue
  ans=""
  for j in range(w):
    if w1[j]==1:
      continue
    ans+=m[i][j]
  print(ans)

Submission status: Accepted

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

rout = [False]*H
for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            rout[i] = True
            break

cout = [False]*W
for i in range(W):
    for j in range(H):
        if grid[j][i] == '#':
            cout[i] = True
            break

for i in range(H):
    for j in range(W):
        if rout[i] and cout[j]:
            print(grid[i][j], end="")
    if rout[i]:
        print("")

Submission status: Accepted

Solution code:
# 2019/03/28
# AtCoder Beginner Contest 107 - B

# Input
h, w = map(int, input().split())
al = list()
wcnt = [0 for i in range(w)]
wh = h

# Input Line and Count # in line
for i in range(h):
    a = input()
    lcnt = 0
    for j in range(w):
        if a[j] == "#":
            wcnt[j] += 1
            lcnt += 1

    if lcnt > 0:
        al.append(a)
    else:
        wh -= 1

# Output Line
for i in range(wh):
    wstr = ""
    for j in range(w):
        if wcnt[j] > 0:
            wstr += al[i][j]
    print(wstr)

Submission status: Accepted

Solution code:
h,w=map(int,input().split());b=[input()for i in range(h)];a=[]
for i in b:
  if i!="."*w:a.insert(0,i)
b=[]
for i in range(w):
  s=""
  for j in a:s=j[i]+s
  if s!="."*len(a):b.insert(0,s)
c=[]
for i in range(len(a)):
  s=""
  for j in b:
    s=j[i]+s
  print(s)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
l=[]
for i in range(a):
    s=input()
    if set(s)=={"."}:
        continue
    else:
        l.append(s)
#print(l)
r=""
l2=[]
for i in range(b):
    for t in range(len(l)):
        r+=l[t][i]
#    print(r)
    if set(r)!={"."}:
        l2.append(r)
    r=""
g=""
#print(l2)
for i in range(len(l2[0])):
    for t in l2:
        g+=t[i]
    print(g)
    g=""

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
grid = []
for h in range(H):
    a = input()
    if '#' in a: #行がすべて白の行ははじめから除く
        grid.append(a)

white = set() #圧縮する列の数字を格納
for w in range(W):
    if all(l[w] == '.' for l in grid): #グリッドの列ごとに走査
        white.add(w)

for l in grid:
    print("".join(l[w] for w in range(W) if w not in white))

Submission status: Accepted

Solution code:
from numpy import*
h,w=int8(input().split())
a=array(eval('list(input()),'*h))
print(*map(''.join,a[any(a<'.',1)][:,any(a<'.',0)]))

Submission status: Accepted

Solution code:
import numpy as np
from sys import stdin
H,W=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(H):
    data.append([ 1 if x == "#" else 0 for x in list(input())])
data=np.array(data)
index_col=[]
for j in range(W):
    if sum(data[:,j]) == 0:
        index_col.append(j)
data=np.delete(data, index_col, 1)

index_row=[]
for k in range(H):
    if sum(data[k]) == 0:
        index_row.append(k)
data=np.delete(data,index_row,0)
for l in data:
    tmp=""
    for m in l:
        if m == 1:
            tmp=tmp+"#"
        else:
            tmp=tmp+"."
    print(tmp)

Submission status: Accepted

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

list_grid = []
for i in range(H):
  list_grid.extend(list(input().split()))

# 行を見る
for i, record in enumerate(list_grid):
  if record == '.' * W:
    list_grid[i] = ''

list_grid = list(filter(lambda s:len(s)>0, list_grid))

import copy
ans = copy.copy(list_grid)

# 列を見る
row = 0
flg = True
while flg:
  tmp = []
  for record in ans:
    tmp.append(record[row])
  
  # 対象列に白しかない場合、その列を削除
  if not ('#' in tmp):
    for i in range(len(ans)):     
      ans[i] = ans[i][:row] + ans[i][row+1:]
  else:
    row += 1
      
  if row == len(ans[0]):
    flg = False


# 出力
for record in ans:
  print(record)

Submission status: Accepted

Solution code:
#107
h, w = map(int, input().split())
h1 = [0]*h
w1 = [0]*w

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

for i in range(h):
    for j in range(w):
        if(a[i][j]=='#'):
            h1[i] = 1
            w1[j] = 1

for i in range(h):
    if h1[i]==1:
        for j in range(w):
            if(w1[j]==1):
                print(a[i][j], end='')
        print()

Submission status: Accepted

Solution code:
H, W = [int(x) for x in input().split()]

grid = []
for h in range(H):
    a = input()
    if '#' in a:
        grid.append(a)

white = set()
for w in range(W):
    if all(l[w] == '.' for l in grid):
        white.add(w)

H = len(grid)

for l in grid:
    print("".join(l[w] for w in range(W) if w not in white))

Submission status: Accepted

Solution code:
from sys import stdin
h,w = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip() for _ in range(h)]
row=[False]*h
col=[False]*w
for i,r in enumerate(data):
    for j,c in enumerate(r):
        if c=='#':
            row[i]=True
            col[j]=True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(data[i][j],end='')
        print()

Submission status: Accepted

Solution code:
H, W = [int(item) for item in input().split()]

l = []
for i in range(H):
  line = input()
  if "#" in line: 
    l.append(line)
  else:
    H -= 1

to_be_deleted = []
for i in range(W):
  white = True
  for line in l:
    if line[i] == "#":
      white = False
      break
  if white:
    to_be_deleted.append(i)
    
for i in to_be_deleted[::-1]:
  for j in range(H):
    if i < W-1:
      l[j] = l[j][:i] + l[j][i+1:]
    else:
      l[j] = l[j][:i]
      
for item in l:
  print(item)

Submission status: Accepted

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

row_ind = np.where(np.all(a==['.']*(np.shape(a)[1]) ,axis=1))
a = np.delete(a, row_ind, axis=0)

col_ind = np.where(np.all(a==[['.']]*(np.shape(a)[0]), axis=0))
a = np.delete(a, col_ind, axis=1)

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a.append([i for i in input()])
h_count = []
for h_ in range(h):
    if a[h_] == ["."] * w:
        h_count.append(h_)
w_count = []
for w_ in range(w):
    if list(map(lambda x: x[w_], a)) == ["."] * h:
        w_count.append(w_)
h_get = [i for i in range(h) if i not in h_count]
w_get = [i for i in range(w) if i not in w_count]

for i in h_get:
    temp = a[i]
    temp_1 = []
    for j in w_get:
        temp_1.append(temp[j])
    print("".join(temp_1))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
grid=[]
grid2=[]
grid3=[]
for i in range(h):
  grid.append(list(input().replace(" ","")))
for i in range(len(grid)):
  if grid[i].count('.')==len(grid[i]):
    pass
  else:
    grid2.append(grid[i])
for i in grid2:
  grid3.append([])
for j in range(len(grid2[0])):
  for i in range(len(grid2)):
    if grid2[i][j]=='#':
      for k in range(len(grid3)):
        grid3[k].append(grid2[k][j])
      break
for i in grid3:
  print(''.join(i))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
point=[0]*w
a=[]
for _ in range(h):
    x=input()
    if x.count("#")!=0:
        a.append(x)
        for i in range(w):
            if x[i]=="#":
                point[i]+=1
for k in range(len(a)):
    s=a[k]
    ans=""
    for j in range(w):
        if point[j]!=0:
            ans+=s[j]
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
a=[list(map(int,input().replace(".","0").replace("#","1"))) for i in range(h)]
a=np.array(a)
c=np.sum(a,axis=1)
a=a[c!=0]
c=np.sum(a,axis=0)
a=a.T[c!=0].T
for i in a.tolist():
    tmp=list((map(lambda x:"." if x==0 else "#",i)))
    print("".join(tmp))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [input() for i in range(h)]
b = [['0']*w for i in range(h)]
for i in range(w):
    cnt = 0
    for j in range(h):
        if a[j][i] == '.':
            cnt += 1
    if cnt != h:
        for p in range(h):
            b[p][i] = a[p][i]
for i in range(len(b)):
    b[i] = [j for j in b[i] if j != '0']
for i in b:
    if ''.join(i) != '.'*len(i):
        print(''.join(i))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
m=[]
for _ in[0]*H:
  l=input()
  if l!='.'*W:m+=[l]
t=[]
for j in range(W):
  f=0
  for l in m:
    if l[j]!='.':f=1;break
  if f:t+=[j]
for l in m:
  print("".join([l[j] for j in t]))

Submission status: Accepted

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

row = []
for i in a:
    if i == '.' * W:
        continue
    row.append(i)

column = []
for i in range(W):
    for j in range(len(row)):
        if row[j][i] == '#':
            column.append(i)
            break

for i in range(len(row)):
    for j in column:
        print(row[i][j], end="")
    print('\n')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
box = []
for i in range(H):
    A = input()
    if not "#" in A:
        continue
    box.append(A)
box_t = []
for i in range(W):
    X = ""
    for j in range(len(box)):
        X += box[j][i]
    if not "#" in X:
        continue
    box_t.append(X)
for i in range(len(box_t[0])):
    for j in range(len(box_t)):
        print(box_t[j][i], end="")
    if i == len(box_t[0]) - 1:
        break
    print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
flag=True
while flag:
    if ['.']*W in a:
        a.remove(['.']*W)
        H-=1
    else:
        flag=False
flag=True
b=[[row[i] for row in a] for i in range(W)]
while flag:
    if ['.']*H in b:
        b.remove(['.']*H)
        W-=1
    else:
        flag=False
a=[[row[i] for row in b] for i in range(H)]
for i in range(H):
    s=''.join(a[i])
    print(s)

Submission status: Accepted

Solution code:
import copy
H,W=map(int,input().split())
a=[input() for i in range(H)]
flag=True
while flag:
    if '.'*W in a:
        a.remove('.'*W)
        H-=1
    else:
        flag=False
b=[0]*H
f=True
while f:
    c=copy.deepcopy(a)
    g=False
    for i in range(W):# i列
        if g:
            break
        for j in range(H):
            b[j]=a[j][i]
        if ''.join(b)=='.'*H:
            for k in range(H):
                s=list(a[k])
                del s[i]
                a[k]=''.join(s)
            W-=1
            g=True
            break
    if c==a:
        f=False
for i in range(H):
    s=''.join(a[i])
    print(s)

Submission status: Accepted

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

for i in range(H):
  if a[i].count(".") == W:
    h[i] = False

for i in range(W):
  cnt = 0
  for j in range(H):
    if a[j][i] == ".":
      cnt += 1
  if cnt == H:
    w[i] = False

for i in range(H):
  for j in range(W):
    if h[i] and w[j]:
      print(a[i][j], end = "")
  if h[i]:
    print("")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    list = [i for i in input()]
    a.append(list)
column = [int(i) for i in range(W)]
row = [int(i) for i in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            if i in row:
                row.remove(i)
            if j in column:
                column.remove(j)
# print(column)
# print(row)
for i in range(H):
    printed = False
    for j in range(W):
        if i not in row and j not in column:
            print(a[i][j], end="")
            printed = True
    if printed:
        print("")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
f = [list(input()) for _ in range(H)]
Y, X = [False for _ in range(H)], [False for _ in range(W)]
for y in range(H):
    for x in range(W):
        Y[y] |= f[y][x] == '#'
        X[x] |= f[y][x] == '#'
for y in range(H):
    flag = False
    for x in range(W):
        if Y[y] and X[x]:
            print(f[y][x], end = "")
            flag = True
    if flag:
        print()

Submission status: Accepted

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

#行削除
for i in range(H):
  a0 = input()
  a1 = set(a0)
  a1 = list(a1)
  if(len(a1) != 1):
   a = list(a0)
   A.append(a) 
   count += 1
  else:
    if(a1[0] != '.'):
     a = list(a0)
     A.append(a) 
     count += 1 
    
#列削除   
j_pop = []
for j in range(W):
 B = [] #Aを縦にカットしたもの
 for i in range(count):  
  B.append(A[i][j])
 B = set(B)
 B = list(B)  
 #カットすべき列
 if(len(B) == 1):
  if(B[0] == '.'):
    j_pop.append(j)  


for i in range(count): 
 ans ='' 
 for j in range(W):
  if(j in j_pop):
    continue
  else:
    ans += A[i][j]
 print(ans)

Submission status: Accepted

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

removable_y = [i for i in range(H)]
removable_x = [i for i in range(W)]

for y in range(H):
    removable = True
    for x in range(W):
        if Ai[y][x] != ".":
            removable = False
            break
    if not removable:
        removable_y.remove(y)

for x in range(W):
    removable = True
    for y in range(H):
        if Ai[y][x] != ".":
            removable = False
            break
    if not removable:
        removable_x.remove(x)

removable_x.reverse()
removable_y.reverse()

for y in removable_y:
    Ai = Ai[:y] + Ai[y + 1:]
for i in range(len(Ai)):
    txt = Ai[i]
    for x in removable_x:
        txt = txt[:x] + txt[x + 1:]
    Ai[i] = txt

for a in Ai:
    print(a)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())

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

h = []
l = []
co = 0
for i in range(n):
    co = 0
    for j in range(m):
        if a[i][j] == "#":
            co = 1
    if co == 0:
        l.append(i)
for i in range(m):
    co = 0
    for j in range(n):
        if a[j][i] == "#":
            co = 1
    if co == 0:
        h.append(i)

for i in range(len(l)):
    a.pop(l.pop())

for i in range(len(h)):
    p = h.pop()
    for j in range(len(a)):
        a[j].pop(p)

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

Submission status: Accepted

Solution code:
import numpy as np
from copy import deepcopy
H, W = map(int, input().split())
A = [list(input()) for _  in range(H)]

output = np.array(A)
A = np.array(A)
delcol = []
delrow = []

for i in range(H):
	if all([A[i][j]=='.' for j in range(W)]):
		delrow.append(i)
		continue
for j in range(W):
	if all([A[i,j]=='.' for i in range(H)]):
		delcol.append(j)

output = np.delete(output, delrow, 0)
output = np.delete(output, delcol, 1)

h, w = output.shape
for i in range(h):
	sentence = ''
	for j in range(w):
		sentence += output[i,j]
	print(sentence)

Submission status: Accepted

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

new_e = []
for row in e:
    if row.count("#") > 0:
        new_e.append(row)

use_col = []
for row in new_e:
    for col in range(W):
        if row[col] == "#" and col not in use_col:
            use_col.append(col)
            
for row in new_e:
    x=""
    for col in sorted(use_col):
        x += row[col]
    print(x)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(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]:
        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 = [input() for i in range(h)]
AnsH=[]
for i in range(h):
    if "#" in A[i]:
        AnsH.append(i)
AnsW=[]
for i in range(w):
    c = 0
    for j in range(h):
        if A[j][i]=="#":
            c = 1
    if c == 1:
        AnsW.append(i)
for i in AnsH:
    for j in AnsW:
        print(A[i][j],end="")

    print()