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())
a = [ list(input()) for _ in range(h) ]

rows = [ False for _ in range(h) ]
cols = [ False for _ in range(w) ]

# 必要な行idを列挙
for y in range(h):
    is_ok = False
    for x in range(w):
        if a[y][x] != ".":
            is_ok = True
    if is_ok:
        rows[y] = True

# 必要な列idを列挙
for x in range(w):
    is_ok = False
    for y in range(h):
        if a[y][x] != ".":
            is_ok = True
    if is_ok:
        cols[x] = True

for y in range(h):
    if not rows[y]:
        continue
    for x in range(w):
        if rows[y] and cols[x]:
            print(a[y][x], end = "")
    print()

Submission status: Accepted

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

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

for w in range(W):
    for h in range(H):
        if res[h][w] == "#":
            break
    else:
        for i in range(H):
            res[i][w] = ""

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

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
I = [input() for i in range(H)]
I_n = [list(j) for j in I if '#' in j]
h = np.array(I_n)
n = 0
for k in range (W):
  if '#' not in h[:, n]:
    h = np.delete(h, n, 1)
  else:
    n += 1
H, W = h.shape
for l in range(H):
  A = ""
  for m in range(W):
    A += h[l, m]
  print(A)

Submission status: Accepted

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

mat=[]
for i in range(H):
  array=[x=="." for x in input()]
  mat.append(array)
#print(mat)

allW_row=[]
for i in range(H):
  allW_line=True
  for j in range(W):
    if not mat[i][j]:
      allW_line=False
      break
  allW_row.append(allW_line)
  
allW_col=[]
for j in range(W):
  allW_line=True
  for i in range(H):
    if not mat[i][j]:
      allW_line=False
      break
  allW_col.append(allW_line)
  
#print(allW_row)
#print(allW_col)
for i in range(H):
  if allW_row[i]:
    continue
    
  array_list=[]
  for j in range(W):
    if not allW_col[j]:
      if mat[i][j]:
        array_list.append(".")
      else:
        array_list.append("#")
  print("".join(array_list))

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=[]
for i in range(H):
  tmp=input()
  if tmp.count("#")==0:
    pass
  else:
    a.append(list(tmp))
else:
  H=len(a)
#print(a)
  
Ignore_tate = []
#たてNGリストアップ
for j in range(W):
  flag=True #除外対象である
  for k in range(H):
    if a[k][j]=="#":
      flag=False
      break
  if flag:
    Ignore_tate.append(j)

for p in range(H):
  str=""
  for q in range(W):
    if q not in Ignore_tate:
      str += a[p][q]
  print(str)

Submission status: Accepted

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

maze = [list(input()) for _ in range(H)]

siro_yoko = []
#w_yoko = [False] * W
for i in range(H):
    w_yoko = [False] * W
    for j in range(W):
        #w_yoko = [False] * W
        if maze[i][j] == '.':
            w_yoko[j] = True
    if all(w_yoko):
        siro_yoko.append(i)
    

siro_tate = []
for j in range(W):
    h_tate = [False] * H
    for i in range(H):
        if maze[i][j] == '.':
            h_tate[i] = True
    if all(h_tate):
        siro_tate.append(j)

for i in range(H):
    yoko = ""
    for j in range(W):
        if not i in siro_yoko and  j not in siro_tate:
            yoko += maze[i][j]
    if yoko:
        print(yoko)
    else:
        print('', end='')

Submission status: Accepted

Solution code:
[h,w] = [int(i) for i in input().split()]
a = []
t = 0
for i in range(h):
    tmp = input()
    if tmp != "." * w:
        a.append(tmp)
    else:
        t += 1
h -= t
ls = []
ans = []
for i in range(w):
    ls.append(i)
for i in range(w):
    intmp = 1
    for j in range(h):
        if a[j][i] == "#":
            intmp *= 0
    if intmp == 1:
        ls.pop(ls.index(i))
for i in range(h):
    tmp = ""
    for j in range(w):
        if j in ls:
            tmp += a[i][j]
    ans.append(tmp)

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

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)

lst = []
for i, row in enumerate(a):
    if np.all(row=='.'):
        lst.append(i)
a = np.delete(a, lst, 0)
b = a.T
lst = []
for i, row in enumerate(b):
    if np.all(row=='.'):
        lst.append(i)
b = np.delete(b, lst, 0)
ans = b.T
for i in ans:
    print(''.join(i))

Submission status: Accepted

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

rev_maze = [[0] * H for i in range(W)]
for i in range(W):
    for j in range(H):
        #rev_maze = 
        rev_maze[i][j] = maze[j][i]

ans_yoko = []
for i in range(H):
    if maze[i].count('.') == W:
        ans_yoko.append(i)
        
ans_tate = []
for i in range(W):
    if rev_maze[i].count('.') == H:
        ans_tate.append(i)

for i in range(H):
    ans = ''
    for j in range(W):
        #ans = ''
        if i in ans_yoko:
            continue
        if j in ans_tate:
            continue
        else:
            ans += maze[i][j]
    if i == any(ans_yoko) - 1:
        print(ans, end='')
    else:
        print(ans)

Submission status: Accepted

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

remove_W = []
remove_dict = {i:0 for i in range(W)}

for i in range(H):
    count_W = 0
    for j in range(W):
        if lists[i][j] == ".":
            remove_dict[j] += 1
            count_W += 1
            if count_W == W:
                remove_W.append(i)
            else:
                continue
remove_H = []
for key, value in remove_dict.items():
    if value == H:
        remove_H.append(key)

remove_H = reversed(remove_H)

for k in remove_H:
    for i in range(H):
        for j in range(W):
            if j == k:
                lists[i].pop(j)
            else:
                continue
remove_W = reversed(remove_W)
# lists_pop = [lists.remove(lists[i]) for i in remove_W]
lists_pop = [lists.pop(i) for i in remove_W]

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
l = list(list(input()) for i in range(h))
for i in l:
  if i.count('.') ==w:
    i.clear()
l= [i for i in l if i!=[]]
#print(l)
t = len(l)
for i in range(w):
  if all (l[q][i]=="." for q in range(t)):
    for q in range(t):
      l[q][i] =""
if "" in l:
  for z in l:
    z.remove("")
for m in l:
  print("".join(m))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [["" for _ in range(w)] for _ in range(h)]
for y in range(h):
    s = input()
    for x in range(w):
        a[y][x] = s[x]
igny = [False] * h
ignx = [False] * w

def YYY(i, j):
    if j == h - 1:
        return a[j][i] == "."
    else:
        if YYY(i, j + 1):
            return a[j][i] == "."
    return False

def XXX(i, j):
    if i == w - 1:
        return a[j][i] == "."
    else:
        if XXX(i + 1, j):
            return a[j][i] == "."
    return False

for x in range(w):
    ignx[x] = YYY(x, 0)

for y in range(h):
    igny[y] = XXX(0, y)

for y in range(h):
    if igny[y] == False:
        for x in range(w):
            if ignx[x] == False:
                print(a[y][x], end = "")
        print()

Submission status: Accepted

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

y = [False]*H
x = [False]*W

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

Submission status: Accepted

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

B=[]
for h in range(H):
    if '#' in A[h]:
        B.append(A[h])

C=[]
for w in range(W):
    C.append([])

for h in range(len(B)):
    for w in range(W):
        C[w].append(B[h][w])

D=[]
for h in range(len(C)):
    if '#' in C[h]:
        D.append(C[h])

E=[]
for w in range(W):
    E.append([])

for h in range(len(D)):
    for w in range(len(D[h])):
        E[w].append(D[h][w])

for h in range(len(E)):
    print("".join(E[h]))

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(h):
    t = input()
    if t=='.'*w: continue
    hw.append(t)
h=len(hw)
check=[0]*w
for i in range(h):
    for j in range(w):
        if hw[i][j]=='#' and check[j]==0:
            check[j]=1
p=0
for j in range(w):
    if check[j]==0:
        for i in range(h):
            hw[i]=hw[i][:j+p]+hw[i][j+1+p:]
        p-=1
for i in range(h):
    print(hw[i])

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[ input() for _ in range(h)]
row=[0]*h
col=[0]*w
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            row[i]+=1
            col[j]+=1

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

Submission status: Accepted

Solution code:

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

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

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

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

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

        print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [input() for i in range(H)]
low = [False]*H
col= [False]*W
for l in range(H):
    for c in range(W):
        if A[l][c] == "#":
            low[l] = True
            col[c] = True
for l in range(H):
    if low[l] ==True:
        for c in range(W):
            if col[c]==True:
                print(A[l][c],end="")
        print()

Submission status: Accepted

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

row = []
for i in range(H):
    if '#' not in F[i]:
        row.append(i)

column = []
for j in range(W):
    if all([F[i][j] == '.' for i in range(H)]):
        column.append(j)

ans = ''
for i in range(H):
    ret = False
    for j in range(W):
        if i not in row and j not in column:
            ans += F[i][j]
            ret = True
    if ret:
        ans += '\n'
print(ans)

Submission status: Accepted

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

HW = [[]]*H
h=0
for _ in range(H):
    Low = input()
    if Low!="."*W:
        HW[h] = list(Low)
        h+=1
        
HW_T = list(zip(*HW[:h]))

hw_t = [[]]*W
w=0

for s in HW_T:
    col= str(''.join(s))
    if col!="."*h:
        hw_t[w] = list(col)
        w+=1

HW = list(zip(*hw_t[:w]))

for l in HW:
    s = str(''.join(l))
    print(s)

Submission status: Accepted

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

valid_h=[]
valid_w=[]

for i in range(h):
    flg=False
    for j in range(w):
        if a[i][j] =="#":
            flg=True
    if flg:
        valid_h.append(i)

for j in range(w):
    flg=False
    for i in range(h):
        if a[i][j] =="#":
            flg=True
    if flg:
        valid_w.append(j)

ans=[]
for i in range(h):
    if not i in valid_h:
        continue

    tmp=[]
    for j in range(w):
        if j in valid_w:
            tmp.append(a[i][j])
    ans.append(tmp)

for a in ans:
    print(*a,sep="")

Submission status: Accepted

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

ans = []
for i in a:
    if "#" in i:
        ans.append(i)

ans_T = list(zip(*ans))
ans = []

for i in ans_T:
    if "#" in i:
        ans.append(i)

ans = list(zip(*ans))

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
L = []
for i in range(h):
    L.append(list(input()))
L = [x for x in L if "#" in x]
L = [x for x in zip(*L)]
L = [x for x in L if "#" in x]
L = [x for x in zip(*L)]
for i in range(len(L)):
    print(*L[i],sep = "")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
h, w = map(int,input().split()) 
a = []
for i in range(h):
    a.append(list(str(input())))

tmp = [[0 for _ in range(w)] for _ in range(h)] 
for i in range(h):
    for j in range(w):
        if a[i][j] == '.':
            tmp[i][j] = 0
        else:
            tmp[i][j] = 1

memo = []
for i in range(h):
    if sum(tmp[i]) == 0:
        memo.append(i)
memo2 = []
for i in range(w):
    sum_tmp = 0
    for j in range(h):
        sum_tmp += tmp[j][i]
    if sum_tmp == 0:
        memo2.append(i)

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h, w = MAP()
a = [list(STR()) for _ in range(h)]
i = 0
while i < len(a):
    if set(a[i]) == set(['.']):
        del a[i]
    else:
        i += 1
j = 0
while j < len(a[0]):
    arr = [a[i][j] for i in range(len(a))]
    if set(arr) == set(['.']):
        for i in range(len(a)):
            del a[i][j]
    else:
        j += 1
for i in range(len(a)):
    print(''.join(a[i]))

Submission status: Accepted

Solution code:
#!python3

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


def main():
    r, c = [], []
    # check rows
    for i in range(H):
        if a[i] != "." * W:
            r.append(i)

    # check columns
    for j in range(W):
        for i in range(H):
            if a[i][j] == "#":
                c.append(j)
                break

    for i in r:
        for j in c:
            print(a[i][j], end="")
        print("")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
board = [input() for i in range(H)]
row, col = [], []
for i in range(H):
    c = sum(board[i][j] == '.' for j in range(W))
    row.append(c != W)
for j in range(W):
    c = sum(board[i][j] == '.' for i in range(H))
    col.append(c != H)
for i in range(H):
    for j in range(W):
        if row[i] and col[j]: print(board[i][j], end='')
    if row[i]: print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
A = []
for i in range(h):
    A.append(list(input()))
B = []
for a in A:
    if "#" in a:
        B.append(a)
C = []
for b in zip(*B):
    if "#" in b:
        C.append(b)
for c in zip(*C):
    print("".join(c))

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())
field = [input() for i in range(h)]

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

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

Submission status: Accepted

Solution code:
import numpy as np


def main():
    h, w = map(int, input().split())
    board = [list(input()) for _ in range(h)]
    board_arr = np.array(board)

    del_h = np.where(np.all(board_arr == '.', axis=1))
    board_arr = np.delete(board_arr, del_h, axis=0)
    del_w = np.where(np.all(board_arr == '.', axis=0))
    board_arr = np.delete(board_arr, del_w, axis=1)
    for row in board_arr:
        row = row.tolist()
        ans = ''.join(row)
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy
h,w = map(int,input().split())
grid = numpy.empty([h,w], str)
white_h = []
white_w = []
for i in range(h):
    grid[i] = list(input())
for i in range(h):
    if "#" not in grid[i]:
        white_h.append(i)
for i in range(w):
    if "#" not in grid[:, i]:
        white_w.append(i)
ans_grid = numpy.empty([h-len(white_h), w-len(white_w)], str)
cnt_h = 0
for i in range(h):
    if i not in white_h:
        cnt_w = 0
        for j in range(w):
            if j not in white_w:
                ans_grid[cnt_h, cnt_w] = grid[i,j]
                cnt_w += 1
        cnt_h += 1
for i in range(len(ans_grid)):
    print("".join(ans_grid[i]))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=['']*H
for i in range(H):
    A[i]=input()
#print(A)
gyou=[False]*H
retu=[False]*W
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            gyou[i]=True
            retu[j]=True
for i in range(H):
    if gyou[i]:
        for j in range(W):
            if retu[j]:
                print(A[i][j],end='')
        print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
a=[x for x in s if '#' in x]
b=[x for x in zip(*a) if '#' in x]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
yoko = [False]*h
tate = [False]*w
for i in range(h):
    s = input()
    a.append(s)
cnt = 0
for i in range(h):
    state = False
    cnt = 0
    for j in range(w):
        if a[i][j] == ".":
            cnt += 1
    if cnt == w:
        yoko[i] = True
cnt = 0
for i in range(w):
    state = False
    cnt = 0
    for j in range(h):
        if a[j][i] == ".":
            cnt += 1
    if cnt == h:
        tate[i] = True

for i in range(h):
    if yoko[i] == True:
        continue
    else:
        ans = ""
        for j in range(w):
            if tate[j] == True:
                continue
            else:
                ans += a[i][j]
        print(ans)

Submission status: Accepted

Solution code:
#abc107  b
h,w=map(int,input().split())
a=[]
gyo=[False]*h
for i in range(h):
    line=input()
    a.append(line)
    if line.count(".")==w:
        gyo[i]=True
retsu=[False]*w
for i in range(w):
    cnt=0
    for j in range(h):
        if a[j][i]==".":
            cnt+=1
    if cnt==h:
        retsu[i]=True

#print(gyo,retsu)
for i in range(h):
    if gyo[i]==False:
        line=""
        for j in range(w):
            if retsu[j]:
                continue
            else:
                line+=a[i][j]
        print(line)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
tmp = []
for h in range(H):
    if set(A[h]) != {'.'}:
        tmp.append(A[h])
H = len(tmp)
ans = [[] for _ in range(H)]

for w in range(W):
    if set(tmp[h][w] for h in range(H)) != {'.'}:
        for h in range(H):
            ans[h].append(tmp[h][w])

for h in range(H):
    print(''.join(map(str, ans[h])))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [None]*H
b = [[1 for j in range(W)] for i in range(H)]
delete = 1
for i in range(0, H):
  a[i] = input()
for i in range(0, H):
  for j in range(0, W):
    if a[i][j] != ".":
      delete = 0
      break
  if delete == 1:
    for j in range(0, W):
      b[i][j] = 0
  else:
    delete = 1
for j in range(0, W):
  for i in range(0, H):
    if a[i][j] != ".":
      delete = 0
      break
  if delete == 1:
    for i in range(0, H):
      b[i][j] = 0
  else:
    delete = 1
new_line = 0
for i in range(0, H):
  for j in range(0, W):
    if b[i][j] == 1:
      print(a[i][j], end = '')
      new_line = 1
  if new_line == 1:
    print(" ")
    new_line = 0

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, product


def resolve():
    h, w = map(int, input().split())
    A = [[_ for _ in input()] for _ in range(h)]
    B = [i for i in A if '#' in i]
    C = zip(*[i for i in zip(*B) if '#' in i])
    for i in C:
        print(*i, sep='')

        # print(*C,sep='')


resolve()

Submission status: Accepted

Solution code:
def resolve():
    h, w = map(int, input().split())
    A = [[_ for _ in input()] for _ in range(h)]
    B = [i for i in A if '#' in i]
    C = zip(*[i for i in zip(*B) if '#' in i])
    for i in C:
        print(*i, sep='')

        # print(*C,sep='')


resolve()

Submission status: Accepted

Solution code:
import bisect
import copy
import fractions
import math
import numpy as np
from collections import Counter, deque
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product


def resolve():
    h, w = map(int, input().split())
    A = [[_ for _ in input()] for _ in range(h)]
    B = [i for i in A if '#' in i]
    C = zip(*[i for i in zip(*B) if '#' in i])
    
    for i in C:
        print(*i, sep='')


resolve()

Submission status: Accepted

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

    for i in range(h):
        for j in range(w):
            if str_list[i][0][j] != '.':
                break
        else:
            for _ in range(w):
                str_list[i][0] = '!' * w
                
    delete_index_list = []

    for i in range(w):
        for j in range(h):
            if str_list[j][0][i] != '.' and str_list[j][0][i] != '!':
                break
        else:
            delete_index_list.append(i)

    for i in range(h):
        for j in range(w):
            if j in delete_index_list:
                continue
            if str_list[i][0][j] != '!':
                print(str_list[i][0][j], end='')
            else:
                break
        else:
            print()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = [[j for j in input()] for i 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:
def is_space(iterable):
    return all(map(lambda x: x == ".", iterable))


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

remove_row_idx = []
for idx, row in enumerate(A):
    if is_space(row):
        remove_row_idx.append(idx)
# print(remove_row_idx)
for count, idx in enumerate(remove_row_idx):
    del A[idx - count]

remove_column_idx = []
for i in range(W):
    column = [r[i] for r in A]
    if is_space(column):
        remove_column_idx.append(i)

for count, idx in enumerate(remove_column_idx):
    for row in A:
        del row[idx - count]

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
#n = int(input())
L = []
for i in range(h):
    tmp = list(input())
    if tmp != ["."]*len(tmp):
        L.append(tmp)
    else:
        h -= 1

l_2d_t = [list(x) for x in zip(*L)]

new_L = []
for i in l_2d_t:
    if i != ["."]*len(i):
        new_L.append(i)

l_2d_t = [list(x) for x in zip(*new_L)]

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[input() for i in range(H)]
useh=[True]*H
usew=[True]*W
for h in range(H):
    cnt=0
    for w in range(W):
        if a[h][w]=='.':
            cnt+=1
    if cnt==W:
        useh[h]=False
for w in range(W):
    cnt=0
    for h in range(H):
        if a[h][w]=='.':
            cnt+=1
    if cnt==H:
        usew[w]=False
for h in range(H):
    if useh[h]:
        for w in range(W):
            if usew[w]:
                print(a[h][w],end='')
        print()

Submission status: Accepted

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

H,W = list(map(int, input().rstrip().split()))
a_list=[list(input().rstrip()) for i in range(H)]
#-----

row_del_list=[]
for i,v in enumerate(a_list):
    if v.count(".") == W:
        row_del_list.append(i)

for i in row_del_list[::-1]:
    del a_list[i]
    H -= 1

       
column_del_list=[]
for j in range(W):
    cnt_white=0
    for i in range(H):
        if a_list[i][j] == ".":
            cnt_white += 1
    
    if cnt_white == H:
        column_del_list.append(j)
        
for j in column_del_list[::-1]:
    for i in range(H):
        del a_list[i][j]
        W -= 1


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

Submission status: Accepted

Solution code:
H,W=map(int,input().split(' '))
a = [list(input()) for i in range(H)]
tmp = []
ans = []
for i in a:
    if i != ['.']*W:
        tmp.append(i)
for i in range(W):
    l = [tmp[j][i] for j in range(len(tmp))]
    if l != ['.']*len(tmp):
        ans.append(l)
for i in range(len(ans[0])):
    print(''.join([ans[j][i] for j in range(len(ans))]))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
for i in range(h-1,-1,-1):
    if set(a[i])=={'.'}: a.remove(a[i])
for i in range(w-1,-1,-1):
    ok = True
    for j in range(len(a)):
        if a[j][i]=='#': ok=False
    if ok:
        for j in range(len(a)):
            a[j] = a[j][:i]+a[j][i+1:]
[print(i) for i in a]

Submission status: Accepted

Solution code:
#ABC107

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

a = [i for i in a if "#" in i]

b = [("").join(list(i)) for i in list(zip(*a))]

b = [i for i in b if "#" in i]

c = [("").join(list(i)) for i in list(zip(*b))]

for i in c:
    print(i)

Submission status: Accepted

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

row = [False]*H
col = [False]*W

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
list_w = []
list_h = []
for i in range(h):
    A = list(str(input()))
    a.append(A)
for i in range(h):
    cnt_w = 0
    cnt_h = 0
    for j in range(w):
        if a[i][j] == ".":
            cnt_w += 1
    if cnt_w == w:
        list_w.append(i)

for i in range(w):
    cnt_h = 0
    for j in range(h):
        if a[j][i] == ".":
            cnt_h += 1
    if cnt_h == h:
        list_h.append(i)

for i in list_w:
    for j in range(w):
        a[i][j] = "!"
for i in list_h:
    for j in range(h):
        a[j][i] = "!"


ans = []
for i in range(h):
    tmp = []
    for j in range(w):
        if a[i][j] == "#" or a[i][j] == ".":
            tmp.append(a[i][j])
    tmp = "".join(tmp)
    ans.append(tmp)
for i in ans:
    if i != '':
        print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[j for j in input()] for i 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())
mas = [list(input()) for i in range(H)]
new_mas = [row for row in mas if "#" in row]
new_mas2 = [column for column in list(zip(*new_mas)) if "#" in column]
for i in list(zip(*new_mas2)):
    for j in i:
        print(j,end="")
    print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
mas = [list(input()) for i in range(H)]
new_mas = []
new_mas2 = []
for row in mas:
    if "#" in row:
        new_mas.append(row)
    elif "#" not in row:
        continue

for column in list(zip(*new_mas)):
    if "#" in column:
        new_mas2.append(column)
    elif "#" not in column:
        continue

for i in list(zip(*new_mas2)):
    for j in i:
        print(j,end="")
    print()