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:
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]
for _ in range(2):
    grid = list(filter(lambda x: '#' in x, grid))
    grid = [list(x) for x in zip(*grid)]
for i in range(len(grid)):
    print(''.join(grid[i]))

Submission status: Accepted

Solution code:
# use transpose by zip
h, w = map(int, input().split())

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

for _ in range(2):
    grid = list(filter(lambda x: any(map(lambda x1: x1 == '#', x)), grid))
    grid = [list(x) for x in zip(*grid)]

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

Submission status: Accepted

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

row = []
col = []
for y in range(h):
    cnt = 0
    for x in range(w):
        if mat[y][x] == ".":
            cnt += 1
    if cnt == w:
        row.append(y)

for x in range(w):
    cnt = 0
    for y in range(h):
        if mat[y][x] == ".":
            cnt += 1
    if cnt == h:
        col.append(x)

for y in range(h):
    tmp = ""
    for x in range(w):
        if x not in col and y not in row:
            tmp += mat[y][x]
    if tmp != "":
        print(tmp)

Submission status: Accepted

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

grid_compred = []
for i in range(H):
    a = input()
    if a != "." * W:
        grid_compred.append(a)

rm_list = []
for i in range(W):
    candidate = [grid_compred[jth][i] for jth in range(len(grid_compred))]
    if ''.join(candidate) == "." * len(grid_compred):
        rm_list.append(i)

for i in range(len(grid_compred)):
    row_list = [grid_compred[i][j] for j in range(len(grid_compred[i])) if j not in rm_list]
    print(''.join(row_list))

Submission status: Accepted

Solution code:
from sys import stdout

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

h = [all(c == '.' for c in a[i]) for i in range(H)]

w = [True] * W
for i in range(H):
  for j in range(W):
    w[j] = w[j] and a[i][j] == '.'

for i in range(H):
  if h[i]:
    continue
  for j in range(W):
    if w[j]:
      continue
    stdout.write(a[i][j])
  stdout.write('\n')

Submission status: Accepted

Solution code:
rows, cols = map(int, input().split())
mat = [input() for _ in range(rows)]

print_row = [False for _ in range(rows)]
print_col = [False for _ in range(cols)]

for i in range(rows):
  for j in range(cols):
    if mat[i][j] == '#':
      print_row[i] = True
      print_col[j] = True

for i in range(rows):
  print_newline = False
  for j in range(cols):
    if print_row[i] and print_col[j]:
      print(mat[i][j], end="")
      print_newline = True
  if print_newline:
    print()

Submission status: Accepted

Solution code:
H,W = [int(x) for x in input().split()]
ans = []
for i in range(H):
  cnt= 0
  S = list(input())
  for j in range(W):
    if S[j]==".":
      cnt +=1
  if cnt!=W:
    ans.append(S)
ans1 = []
for j in range(len(ans[0])):
  cnt = 0
  for i in range(len(ans)):
    if ans[i][j]==".":
      cnt+=1
  if cnt ==len(ans):
    ans1.append(j)
for i in range(len(ans)):
  for j in ans1:
    ans[i][j]=0
for i in range(len(ans)):
  for j in range(len(ans[0])):
    if ans[i][j] !=0:
    	print(ans[i][j],end="")
  print()

Submission status: Accepted

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

    def rotate_clockwise(matrix):
        return list(map(list, zip(*matrix)))[::-1]

    def rotate_counterclockwise(matrix):
        return list(map(lambda x: list(x[::-1]), zip(*matrix)))

    def remove_white_line(matrix):
        return [row for row in matrix if row.count('.') < len(row)]

    ans = rotate_counterclockwise(remove_white_line(rotate_clockwise(remove_white_line(A))))
    return '\n'.join([''.join(row) for row in ans])

print(b_grid_compression())

Submission status: Accepted

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

box_t=[[] for _ in range(len(box_y))]
for i in range(w):
    if any(["#"==box_y[j][i] for j in range(len(box_y))]):
        for j in range(len(box_y)):
            box_t[j].append(box_y[j][i])

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a_list = [list(input()) for _ in range(H)]
dot_cnt = [sum([a == '.' for a in a_col]) for a_col in a_list]
exist_idx = [i for i, num in enumerate(dot_cnt) if num != W]

st = set(range(W))

for i in exist_idx:
    dot_idx = [i for i, a in enumerate(a_list[i]) if a == '.']
    st = st & set(dot_idx)

for i in exist_idx:
    print(''.join([a for i, a in enumerate(a_list[i]) if i not in st]))

Submission status: Accepted

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

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

row = [False] * h
col = [False] * w
for i in range(h):
  for j in range(w):
    if pic[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(pic[i][j], end = "")
    print()

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
a = [input() for _ in range(h)]
l = []
ans = []
for i in a:
    if i == "."*w:continue
    l.append(i)
for i in zip(*l):
    if "".join(i) == "."*len(i):continue
    ans.append("".join(i))
for i in zip(*ans):
    print("".join(i))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [list(input()) for h in range(H)]
A1 = [a for a in A if '#' in a]
A2 = [a for a in zip(*A1) if '#' in a]
A3 = [a for a in zip(*A2)]
for a in A3:
    print(''.join(a))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [input() for _ in range(H)]
B = [A[h] for h in range(H) if '#' in A[h]]

rem = []
for w in range(W):
    col = [B[i][w] for i in range(len(B))]
    if '#' not in col:
        rem.append(w)

for h in range(len(B)):
    for w in range(W):
        if w not in rem:
            print(B[h][w], end="")
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for i in range(h)]
b=[i for i in a if i.count("#")>0]
for i in range(w-1,-1,-1):
    if sum([b[j][i]=="#" for j in range(len(b))])==0:
        for k in range(len(b)):
            b[k]=b[k][:i]+b[k][i+1:]
print(*b,sep="\n")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = []
for h in range(H):
    a = input()
    if '#' in a:
        A.append(a)
A = [a for a in zip(*A) if '#' in a]
A = [a for a in zip(*A)]
for a in A:
    print(''.join(a))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [list(input()) for h in range(H)]
A = [a for a in A if '#' in a]
A = [a for a in zip(*A) if '#' in a]
A = [a for a in zip(*A)]
for a in A:
    print(''.join(a))

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
A = [input() for h in range(H)]
A = [list(a) for a in A if '#' in a]
w = 0
while w < W:
    for a in A:
        if a[w]=='#':
            break
    else:
        for a in A:
            a.pop(w)
        W -= 1
        w -= 1
    w += 1
for a in A:
    print(''.join(a))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for _ in range(h):
    l = input()
    if l != '.'*w:
        a.append(l)
col = []
h = len(a)
for i in range(w):
    if a[0][i] == '.':
        for j in range(1,h):
            if a[j][i] != '.':
                col.append(i)
                break
    else:
        col.append(i)
for l in a:
    ll = ''
    for i in col:
        ll += l[i]
    print(ll)

Submission status: Accepted

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

y = []
for i, name in enumerate(n):
    if not all([j == "." for j in name]):
        y.append(name)

nc = []
for _ in range(len(y[0])):
    nnc = []
    for _ in range(len(y)):
        nnc.append("#")
    nc.append(nnc)

for i, name in enumerate(y):
    for k, name2 in enumerate(name):
        nc[k][i] = name2

z = []
for i, name in enumerate(nc):
    if not all([j == "." for j in name]):
        z.append(name)

nc = []
for _ in range(len(z[0])):
    nnc = []
    for _ in range(len(z)):
        nnc.append("#")
    nc.append(nnc)

for i, name in enumerate(z):
    for k, name2 in enumerate(name):
        nc[k][i] = name2

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

Submission status: Accepted

Solution code:
# ABC107b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

ansX = []
ansY = []

for y in range(h):
    flag = True
    for x in range(w):
        if (a[y][x] == '#'):
            flag = False
    if (flag):
        ansY.append(y)

for x in range(w):
    flag = True
    for y in range(h):
        if (a[y][x] == '#'):
            flag = False
    if (flag):
        ansX.append(x)
#print(ansX, ansY)
for y in range(h):
    if (y in ansY):
        continue
    for x in range(w):
        if (x in ansX):
            continue
        print(a[y][x], end='')
    print('')

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [input() for i in range(h)]
a = [i for i in a if i!="."*w]
import numpy as np
flag = [[int(j) for j in i.replace(".","0").replace("#","1")] for i in a]
flagx = np.sum(flag,axis=0) > 0
d = {0:".",1:"#"}
for i in a:
  for j,b in zip(i,flagx):
    if b:
      print(j, end="")
  print()

Submission status: Accepted

Solution code:
# ABC107B - Grid Compression
def main():
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    X, Y = [0] * H, [0] * W
    for i, a in enumerate(A):
        for j, x in enumerate(a):
            if x == "#":
                X[i], Y[j] = 1, 1
    ans = []
    for i, x in enumerate(X):
        cur = ""
        for j, y in enumerate(Y):
            if x and y:
                cur += A[i][j]
        if cur:
            ans.append(cur)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
matrix = [list(input()) for j in range(H)]
A = []
for line in range(H):
    if matrix[line].count('.') != W:
        A.append(matrix[line])
B = [] # extract rows
for row in range(W):
    flg = True
    for line in range(len(A)):
        if A[line][row] == '#':
            flg = False
    if flg == True:
        B.append(row)
C = [] # answer
for line in range(len(A)):
    for b in sorted(B, reverse=True):
        A[line].pop(b)
    C.append(A[line])
for c in C:
    print(''.join(c))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
matrix = [list(input()) for j in range(H)]
#print(matrix)
A = []
for line in range(H):
    #print(matrix[line])
    if matrix[line].count('.') != W:
        A.append(matrix[line])
#print('after line:', A)
B = [] # extract rows
for row in range(W):
    flg = True
    for line in range(len(A)):
        if A[line][row] == '#':
            flg = False
    if flg == True:
        B.append(row)
#print(B)
C = []
for line in range(len(A)):
    for b in sorted(B, reverse=True):
        A[line].pop(b)
    C.append(A[line])
for c in C:
    print(''.join(c))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[]
for _ in range(H):
  a.append(list(map(lambda x: 1 if x=="#" else 0,list(input()))))
#print(a)

b=[]
for i in range(H):
  if sum(a[i])!=0:
    b.append(a[i])
#print(b)

c=[]
for j in range(W):
  cnt=0
  for i in range(len(b)):
    cnt+=b[i][j]
  c.append(cnt)
#print(c)

d=[]
for i in range(len(b)):
  dd=[]
  for j in range(W):
    if c[j]!=0:
      dd.append(b[i][j])
  d.append(dd)
#print(d)

for i in range(len(d)):
  print("".join(list(map(lambda x: "." if x==0 else "#",d[i]))))

Submission status: Accepted

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

import copy

H,W = map(int,input().split())
a = [list(input().split()) for _ in range(H)]
for i in range(H):
    a[i] = list(a[i][0])
a_copy = copy.copy(a)
ans = [[] for _ in range(H)]
h=0
for i in range(H):
    Flag = True
    for j in range(W):
        if a[i][j] != ".":
            Flag = False
            break
    if not(Flag):
        for j in range(W):
            ans[h].append(a[i][j])
        h+=1
ans_H=h

ans2 = [[] for _ in range(H)]

for i in range(W):
    Flag = True
    for j in range(ans_H):
        if ans[j][i] != ".":
            Flag = False
            break
    if not(Flag):
        for j in range(ans_H):
            ans2[j].append(ans[j][i])


for i in range(ans_H):
    print("".join(ans2[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
a = [c for c in zip(*a) if '#' in c]
a = [r for r in zip(*a) if '#' in r]
for r in a:
    print(''.join(r))

Submission status: Accepted

Solution code:
import os, sys, re, math

def dorow(N):
    cnt = 0
    for i in range(1, N+1):
        if N % i == 0:
            cnt += 1
    return cnt

H,W = map(int,input().split(' '))
table = []
for h in range(H):
    tmp = input()
    if tmp != '.' * W:
        table.append(tmp)

ret = ['' for _ in range(len(table))]

for i in range(W):
    flg = False
    for j in range(len(table)):
        if table[j][i] == '#':
            flg = True
            break

    if flg:
        for j in range(len(table)):
            ret[j] += table[j][i]

for r in ret:
    print(r)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

a = [''.join(r) for r in zip(*a)]
a = filter(lambda r: '#' in r, a)
a = [''.join(r) for r in zip(*a)]

for r in list(a):
    print (r)

Submission status: Accepted

Solution code:
line = raw_input()
H, W = [int(s) for s in line.split(' ')]
lines = []
ret = [0] * W
for h in range(0, H):
    line = raw_input()
    A = [0 if s == '.' else 1 for s in line]
    if all([a == 0 for a in A]):
        continue
    lines.append(line)
    ret = [i + j for i, j in zip(ret, A)]
for line in lines:
    print ''.join([c for i, c in zip(range(0, W), line) if ret[i] > 0])

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split(' ')))
ll = []
for i in range(N):
    l = [c != '.' for c in input()]
    if (any(l)):
        ll.append(l)
tll = [list(x) for x in zip(*ll)]
tans = []
for i in range(len(tll)):
    if (any(tll[i])):
        tans.append(tll[i])
        
ans = [list(x) for x in zip(*tans)]
for i in range(len(ans)):
    print(''.join(['#' if c else '.' for c in ans[i]]))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
B=[]
C=[]
ans=[]
for i in range(H):
  if '#' in A[i]:
    B.append(A[i])
C=list(zip(*B))
for i in range(W):
  if '#' in C[i]:
    ans.append(C[i])
ans=list(zip(*ans))
for k in range(len(ans)):
  print(*ans[k],sep='')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
*l,=eval("input(),"*h)
row=[any(l[i][j]=="#" for i in range(h)) for j in range(w)]
col=["#" in l[i] for i in range(h)]
for i in range(h):
	f=0
	for j in range(w):
		if row[j]&col[i]:
			print(l[i][j],end="")
			f=1
	if f:
		print("")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
h,w= [],[]
a = [list(input()) for i in range(n)]
b = [i for i in zip(*a)]
for i in range(n):
    if a[i].count(".") == len(a[i]):
        h.append(i)

h = sorted(h,reverse=True)
while h:
    del a[h[0]]
    del h[0]

for i in range(m):
    if b[i].count(".") == len(b[i]):
        w.append(i)

w = sorted(w,reverse=True)
while w:
    for i in range(len(a)):
        del a[i][w[0]]
    del w[0]

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [input() for i in range(H)]
B = []
for a in A:
    if not all([x == '.' for x in a]):
        B.append(a)
C = zip(*[b for b in zip(*B) if '#' in b])
for c in C:
    print(*c, sep='')

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

Submission status: Accepted

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

# 行を削除
for i in range(h-1, -1, -1):
    if '#' not in a[i]:
        del a[i]

# 列を削除
h = len(a)
for i in range(w-1, -1, -1):
    res = True
    for j in range(h):
        if a[j][i] == '#':
            res = False
    if res:
        for j in range(h):
            del a[j][i]
for i in range(len(a)):
    print("".join(a[i]))

Submission status: Accepted

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

Submission status: Accepted

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

x=[False]*w
y=[False]*h

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            x[j]=True
            y[i]=True


for i in range(h):
    li=[]
    for j in range(w):
        if x[j]==True and y[i]==True:
            li+=a[i][j]
    if li!=[]:
        print(''.join(li))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
ls = [l for l in ls if l.count('.') < w]


def transpose(ls):
    res = []
    h = len(ls)
    w = len(ls[0])
    for j in range(w):
        l = ''
        for i in range(h):
            l += ls[i][j]
        res.append(l)
    return res


h = len(ls)
ls = transpose([l for l in transpose(ls) if l.count('.') < h])

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

Submission status: Accepted

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

for h in range(H): #行から見ていきます
  f = True
  for w in range(W):
    if A[h][w] != ".":
      f = False
  if not f:
    Hlist.append(h)
for w in range(W): #行から見ていきます
  f = True
  for h in range(H):
    if A[h][w] != ".":
      f = False
  if not f:
    Wlist.append(w)

Aout = []

for h in Hlist:
  a = ""
  for w in Wlist:
    a += A[h][w]
  Aout.append(a)

for aout in Aout:
  print(aout)

Submission status: Accepted

Solution code:
import numpy as np

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

for z in zentai[:]:
  if "#" not in z:
    zentai.remove(z)

tr=np.array(zentai)
tr=tr.T
tr=tr.tolist()

for z in tr[:]:
  if "#" not in z:
    tr.remove(z)

tr=np.array(tr)
tr=tr.T
tr=tr.tolist()

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[[i for i in input()] for _ in range(H)]
B=[x for x in A if '#' in x]
C=zip(*[y for y in zip(*B) if '#' in y])
for d in C:
  print(''.join(d))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
A = [list(input()) for i in range(h)]
White_rows = []
for i in range(h):
    if A[i] == ['.' for j in range(w)]:
        White_rows += [i]
White_rows.sort(reverse=True)
for row in White_rows:
    A.pop(row)
White_cols = []
for i in range(w):
    if all([A[j][i] == '.' for j in range(len(A))]):
        White_cols += [i]
White_cols.sort(reverse=True)
for col in White_cols:
    for j in range(len(A)):
        A[j].pop(col)
for a in A:
    print(*a,sep='')

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
grid=[""]*H
del_list=[[],[]]
for i in range(H):
  grid[i]=list(input())
  if grid[i]==["." for j in range(W)]:
    del_list[0].append(i)

for i in range(W):
  tmp=[grid[x][i] for x in range(H)]
  if tmp == ["." for j in range(H)]:
    del_list[1].append(i)
    
for i in reversed(range(len(del_list[0]))):
  grid.pop(del_list[0][i])
  
for i in reversed(range(len(del_list[1]))):
  for j in range(len(grid)):
    grid[j].pop(del_list[1][i])

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

Submission status: Accepted

Solution code:
def tenchi(gr):
    gr_t=[[0]*len(gr) for i in range(len(gr[0]))]
    for i in range(len(gr)):
        for j in range(len(gr[i])):
            gr_t[j][i] = gr[i][j]
    return gr_t

H, W = map(int,input().split())
a=[list(input()) for i in range(H)]
#yoko
while a.count(["."]*len(a[0]))>0:
    a.remove(["."]*len(a[0]))

a_t = tenchi(a)
while a_t.count(["."]*len(a_t[0]))>0:
    a_t.remove(["."]*len(a_t[0]))
ans = tenchi(a_t)
for i in range(len(ans)):
    ansa = "".join(ans[i])
    print(ansa)

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:
# coding: utf-8
import numpy as np
H, W = map(int, input().split())
maze = []
#入力の時点で行で削れるとことは削る
for _ in range(H):
    s = list(input())
    if s != ["."]*W:
        maze.append(s)
maze = np.array(maze)
#列で削れるところを削る
undels = []
for i in range(maze.shape[1]):
    if sum(maze[:, i] == ".") != maze.shape[0]:
        undels.append(i)
ans = maze[:, undels]
for i in range(ans.shape[0]):
    print(*ans[i], sep="")

Submission status: Accepted

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

for j in ans:
  print(*j, sep='')

Submission status: Accepted

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

for i in range(h):
    m.append(list(input()))


#行に着目
dl = []

for i in range(h):
    if all(j =='.' for j in m[i]):
        dl.append(int(i))
# print(dl)
if dl:
    for i in dl:
        del m[i-dl.index(i)]
h = len(m)
# print(m)

dl = []
for i in range(w):
    s = ''
    for j in range(h):
        s = s + m[j][i]
    if all(j == '.' for j in list(s)):
        dl.append(int(i))
# print(dl)
if dl:
    for i in range(h):
        for j in dl:
            del m[i][j-dl.index(j)]

# print(m)
for i in range(h):
    print(''.join(m[i]))

#転置して同様
# m = list(zip(*m)) 
# if m:
#     dl = []
#     for i in range(w):
#         if all(j =='.' for j in m[i]):
#             dl.append(int(i))

#     if dl:
#         for i in range(len(dl)):
#             del m[dl[len(dl)-i-1]]
            


# #転置して元に戻す
# m = list(zip(*m))


# #出力
# for i in range(len(m)):
#     m[i] = ''.join(m[i])
#     print(m[i])

Submission status: Accepted

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

row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            row[i] = True
            col[j] = True

for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j],end = '')
        print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [input() for i in range(H)]
ans = []
for i in range(H):
    flag = 0
    for j in range(W):
        if A[i][j] == "#":
            flag = 1
    if flag == 1:
        ans.append(A[i])
H2 = len(ans)
W2 = len(ans[0])
ans2 = []
for j in range(W2):
    flag = 0
    for i in range(H2):
        if ans[i][j] == "#":
            flag = 1
    if flag == 1:
        ans2.append(j)
Ans = []  
for i in range(H2):
    Ans.append([])
    for j in ans2:
        Ans[i].append(ans[i][j])
        
W3 = len(Ans[0])
for i in range(H2):
    tmp = ""
    for j in range(W3):
        tmp += Ans[i][j]
    print(tmp)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    tmp=str(input())
    if '#' in tmp:
        a.append(tmp)
delete=[-1]
for i in range(w):
    for j in range(len(a)):
        if a[j][i]=='#':
            break
        else:
            if j==len(a)-1:
                delete.append(i)
if delete==[]:
    delete.append(w)
for i in range(len(a)):
    for j in range(1,len(delete)):
        print(a[i][delete[j-1]+1:delete[j]],end="")
    if delete[-1]<w-1:
        print(a[i][(delete[-1]+1):],end="")
    print("")

Submission status: Accepted

Solution code:
# ABC108 B - GridCompression 
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
A = [list(input()) for _ in range(h)]
B = []
C = []
for Row in A:
    if set(Row)!={'.'}: B.append(Row)
B = [Row for Row in zip(*B)]
for Row in B:
    if set(Row)!={'.'}: C.append(Row)
for Row in zip(*C):
    print(''.join(Row))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
  As = input()
  if As.find("#") < 0:
    H -= 1
  else:
    A.append(As)
j = 0
while j < W:
  b = True
  for As in A:
    if As[j] == "#":
      b = False
  if b:
    W -= 1
    for i in range(len(A)):
      A[i] = A[i][:j]+A[i][j+1:]
  else:
    j += 1
for i in range(H):
  As = A[i]
  print(As)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
grid=[input() for i in range(H)]
h=[]
w=[]
for i in range(H):
    for j in range(W):
        if grid[i][j]=='#':
            h.append(i)
            w.append(j)
h=list(set(h))
w=list(set(w))
for i in h:
    p=''
    for j in w:
        p+=grid[i][j]
    print(p)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
g=''
g2=''
h_removed=0
w_removed=0
for i in range(H):
    ip=input()
    if ip=='.'*W:
        h_removed+=1
    else:
        g+=ip
        
for i in range(W):
    col=''
    for j in range(H-h_removed):
        col+=g[i+j*W]
    if col=='.'*(H-h_removed):
        w_removed+=1
    else:
        g2+=col
        
for i in range(H-h_removed):
    p=''
    for j in range(W-w_removed):
        p+=g2[i+j*(H-h_removed)]
    print(p)

Submission status: Accepted

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

a=[list(input()) for i in range(H)]
l_idx=[]
c_idx=[]
for i in range(H):
    for j in range(W):
        if a[i][j]=="#":
            l_idx.append(i)
            c_idx.append(j)

for i in range(W-1,-1,-1):
    if not i in c_idx:
        for j in range(H):
            a[j].pop(i)

for i in range(H):
    if i in l_idx:
        print("".join(a[i]))

Submission status: Accepted

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

a=[list(input()) for i in range(H)]
l_idx=[]
c_idx=[]
for i in range(H):
    for j in range(W):
        if a[i][j]=="#":
            l_idx.append(i)
            c_idx.append(j)

for i in range(W-1,-1,-1):
    if not i in c_idx:
        for j in range(H):
            a[j].pop(i)

for i in range(H):
    if i in l_idx:
        print("".join(a[i]))

Submission status: Accepted

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

for i in range(W):
    cnt=0
    for j in range(1,H):
        if a[0][i]=="." and a[0][i]==a[j][i]:
            cnt+=1
            if cnt==H-1:
                rmidx.append(i)
        else:
            break


for i in range(H):
    for j in reversed(rmidx):
        a[i].pop(j)

rmidx=[]

for i in range(H):
    if a[i].count("#")==0:
        rmidx.append(i)

for i in range(H):
    if not i in rmidx:
        print("".join(a[i]))

Submission status: Accepted

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

h_d = []
for i in range(h):
    cnt = 0
    for j in range(w):
        if a[i][j] != '.':
            break
        cnt += 1
    if cnt == w:
        h_d.append(i)
a = [a[i] for i in range(h) if i not in h_d]

h_ = len(a)
w_d = []
for j in range(w):
    cnt = 0
    for i in range(h_):
        if a[i][j] != '.':
            break
        cnt += 1
    if cnt == h_:
        w_d.append(j)
a = [[a[j][i] for i in range(w) if i not in w_d]for j in range(h_)]

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[]
for _ in range(H):
    a=list(input())
    if sum(list(map(ord, a)))==ord(".")*W:
        continue
    A.append(a)

B=[]
for a in zip(*A):
    if sum(list(map(ord, a)))==ord(".")*len(a):
        continue
    B.append(a)

for b in zip(*B):
    print("".join(b))

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

H, W = ISI()
a = [[j for j in IS()] for i in range(H)]
b = []
for x in a:
    if "#" in x:
        b.append(x)
c = []
for y in zip(*b):
    if "#" in y:
        c.append(y)
for a in zip(*c):
    print("".join(a))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for _ in range(h):
    _a = list(input())
    if '#' in _a:
        a += [_a]
    else:
        pass

import numpy as np

a = np.array(a)
ans_col = []

for i in range(w):
    if '#' in a[:,i]:
        ans_col += [i]
    else:
        pass

ans = a[:, ans_col]

for j in range(a.shape[0]):
    print(''.join(map(str, ans[j, :])))