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:
import functools
import numpy as np


def get_bool(x, value, axis):
    return np.where(x == value, True, False).all(axis=axis)


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

custom_get_bool = functools.partial(get_bool, mat, '.')
mat = mat[:, ~custom_get_bool(0)]
mat = mat[~custom_get_bool(1)]
print('\n'.join([''.join(row) for row in mat]))

Submission status: Accepted

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


def get_bool(x, value, axis):
    return np.where(x == value, True, False).all(axis=axis)


mat = mat[:, ~get_bool(mat, '.', 0)]
mat = mat[~get_bool(mat, '.', 1)]
print('\n'.join([''.join(row) for row in mat]))

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
mat = np.array([list(input()) for _ in range(H)])
mat = mat[:, ~np.where(mat == '.', True, False).all(axis=0)]
mat = mat[~np.where(mat == '.', True, False).all(axis=1)]

print('\n'.join([''.join(row) for row in mat]))

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
mat = np.array([list(input()) for _ in range(H)])
bools = np.where(mat == '.', True, False)
mat = mat[:, ~bools.all(axis=0)]
bools = np.where(mat == '.', True, False)
mat = mat[~bools.all(axis=1)]

print('\n'.join([''.join(row) for row in mat]))

Submission status: Accepted

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

# 列から確認
ans = []
for i in range(H):
    row = mat[i]
    if all(['.' == r for r in row]):
        continue
    ans.append(row)

columns = [''.join([a[w] for a in ans]) for w in range(W)]
tmp = len(ans)
columns = [c for c in columns if '.' * tmp != c]

ans = [''.join([c[i] for c in columns]) for i in range(len(columns[0]))]
print('\n'.join(ans))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
delcol = {i: True for i in range(w)}
for _ in range(h):
    _a = input()
    if _a == "."*w:
        continue

    for _w in range(w):
        delcol[_w] &= ("." == _a[_w])

    a.append(_a)

for _a in  a:
    for _w in range(w):
        if not delcol[_w]:
            print(_a[_w], end="")

    print()

Submission status: Accepted

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

for i in range(H):
  if a[i] == "." * W:
    h.append(i)
  for j in range(W):
    if a[i][j] == ".":
      w.append(j)

w_set = list(set(w))
for x in range(len(w_set)):
  if w.count(w_set[x]) == H:
    w_list.append(w_set[x])

for i in range(H):
  A = ""
  if a[i] != "." * W:
    for j in range(W):
      if not j in w_list:
        A += a[i][j]
    print(A)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = [ input() for _ in range(h) ]
H, W = [], []
for i in range(h):
    if A[i].count('.')==w:
        H.append(i)
for j in range(w):
    if [ A[i][j] for i in range(h) ].count('.')==h:
        W.append(j)
for i in range(h):
    if i in H:
        continue
    for j in range(w):
        if j in W:
            continue
        print(A[i][j], end='')
    print()

Submission status: Accepted

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

Submission status: Accepted

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

A = ""

for _ in range(H):
  s = input()
  if len(set(s)) == 1 and s == "." * W:
    H -= 1
  else:
    for i in s:
      A += i

if len(A) == 0:
  print(A)

else:
  M = []

  for i in range(W):
    if A[i] == ".":
      for j in range(i + W,H * W,W):
        if A[j] == "#":
          break
      else:
        M.append(i)

  A = [A[i] for i in range(H * W) if not (i % W) in M]
  W = W - len(M)
  
  S = ""
  
  for i in range(H * W):
    S += A[i]
    if (i + 1) % W == 0:
      print(S)
      S = ""

Submission status: Accepted

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

Submission status: Accepted

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

use_cols = []
use_rows = []

for hi in range(h):
  flag = False
  for wi in range(w):
    if aa[hi][wi] == '#':
      flag = True
      break
  if flag:
    use_rows.append(hi)

for wi in range(w):
  flag = False
  for hi in range(h):
    if aa[hi][wi] == '#':
      flag = True
      break
  if flag:
    use_cols.append(wi)
    
ans = [[' ']*(w-len(use_cols)) for _ in range(h-len(use_rows))]

ans =[]
for hi in use_rows:
  row = ''
  for wi in use_cols:
    row+=aa[hi][wi]
  ans.append(row)
  
for a in ans:
  print(a)

Submission status: Accepted

Solution code:
import sys

h, w = map(int, sys.stdin.readline().split())
grid = [sys.stdin.readline().rstrip() for _ in range(h)]

def main():
    res = [list(s) for s in grid if '#' in s]
    res2 = []
    for j in range(w):
        t = [s[j] for s in res]
        if '#' in t:
            res2.append(t)
    
    for j in range(len(res)):
        yield ''.join([s[j] for s in res2])

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

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

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

    if '#' in wk:
        a.append(wk)

t = []
for j in zip(*a):
    if '#' in j:
        t.append(j)

for list in zip(*t):
    print("".join(list))

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))



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

ans1 = []
ans2 = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    if not("#" in a[i]):
        continue
    else:
        ans1.append(a[i])

cnt = 0
for i in range(w):
    bre = True
    for j in range(len(ans1)):
        if ans1[j][i] == "#":
            bre = False
    if not(bre):
        for k in range(len(ans1)):
            ans2[k][cnt] =  ans1[k][i]
        cnt += 1

for i in range(h):
    for j in range(w):
        if ans2[i][j] != 0:
            print(ans2[i][j],end="")
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
table = []
for _ in range(h):
    line = input()
    if line.count(".") != w:
        table.append(line)
table = [list(x) for x in zip(*table)]
ans = []
for t in range(len(table)):
    if table[t].count(".") != len(table[t]):
        ans.append(table[t])
ans = [list(x) for x in zip(*ans)]
for a in ans:
    print("".join(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

grid=[]
result=[]

for i in range(h):
    buf=input()
    if len(buf) == buf.count("."):
        continue
    else:
        grid.append(buf)

for x in zip(*grid):
    if len(x) == x.count("."):
        continue
    else:
        result.append(x)

for x in zip(*result):
    print("".join(x))

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(input().strip()) for _ in range(H)]
a = [ai for ai in a if "#" in ai]
H = len(a)
a_T = np.array(a).T
a_T = [ai for ai in a_T if "#" in ai]
a = np.array(a_T).T
W = len(a[0])
for i in range(H):
    for j in range(W):
        print(a[i][j],end="")
    print("")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
H,W = [int(i) for i in input().split()]
nes = ['0'] * H
for i in range(H) :
    li = list(input())
    nes[i] = li
yoko = [False] * H
tate = [False] * W
for i in range(H) :
    for j in range(W) :
        if nes[i][j] == "#" :
            yoko[i] = True
            tate[j] = True
for i in range(H) :
    if yoko[i] :
        for j in range(W) :
            if tate[j] :
                print(nes[i][j],end = '')
        print()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
H,W = [int(i) for i in input().split()]
nes = ['0'] * H
indexa = []
for i in range(H) :
    li = list(input())
    nes[i] = li
for i in range(H) :
    del nes[i][-1]
a = 0
for i in range(H) :
    for j in range(W) :
        if nes[i][j] == "#" :
            a = 1
            break
    if a == 0 and nes[i][W-1] == "." :
        indexa.append(i)
    a = 0
count = 0
for i in indexa :
    del nes[i-count]
    count+=1
length = len(nes)
indexaa = []
b = 0
for j in range(W) :
    for i in range(length) :
        if nes[i][j] == "#" :
            b = 1
            break
    if nes[length-1][j] == "." and b == 0 :
        indexaa.append(j)
    b = 0
counta = 0
for i in indexaa :
    for j in range(length) :
        del nes[j][i-counta]
    counta+=1
for i in range(length) :
    t = ''.join(nes[i])
    print(t)

Submission status: Accepted

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

    A = []
    grid = []
    for i in range(h):
        A.append(input())
    gird = []

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

    A = grid.copy()
    w_tmp = len(A[0])
    h_tmp = len(A)
    grid = ['' for _ in range(h_tmp)]
    for i in range(w_tmp):
        tmp = 0
        for j in range(h_tmp):
            if A[j][i] == '.':
                tmp += 1
        if tmp != h_tmp:
            for j in range(h_tmp):
                grid[j] += A[j][i]
    for i in range(len(grid)):
        print(grid[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
i,j=map(int,input().split())
li=[]
for s in range(i):
    p=str(input())
    li.append(p)
def provre(x):
    lll=0
    br=0
    for z in range(len(x)):
        if x[z]=='.':
            br+=1
    if br==len(x):
        lll=1
    return(lll)
li2=[]
for a in range(len(li)):
    if provre(li[a])==0:
        li2.append(li[a])
li=li2

def prost(x):
    sd=[]
    L = [1] * len(x[0])
    for i in range(len(x[0])):
        ooo=1
        cnt = 0
        for s in range(len(x)):
            if x[s][i]=='.':
                cnt += 1
        if cnt == len(x):
            ooo = 0
        if ooo==0:
            L[i] = 0
              
    for j in range(len(x)):
        s = ""
        for q in range(len(x[0])):
            if L[q]==1:
                s+=x[j][q]
        sd.append(s)
    for ka in range(len(sd)):
        print(sd[ka])


prost(li)

Submission status: Accepted

Solution code:


def provjera(listaznakova):
    x = 0
    for znak in listaznakova:
        if znak == ".":
            x = x+1
    if x == len(listaznakova):
        return False
    else:
        return True
            
    
h,w = map(int,input().split())
matrica = []
matrica_dva = []
matrica_tri = []
matrica_cet = []
matrica_rez = []
red_t = []



for x in range(h):
    red=input()
    matrica.append(red)
    
for c in matrica:
    if provjera(c):
        matrica_dva.append(c)
    else:
        h-=1
    
for x in range(w):
    for y in range(h):
        red_t.append(matrica_dva[y][x])
    matrica_tri.append(red_t)
    red_t = []

for c in matrica_tri:
    if provjera(c):
        matrica_cet.append(c)
    else:
        w-=1
red_t = []

for x in range(h):
    for y in range(w):
        red_t.append(matrica_cet[y][x])
    matrica_rez.append(red_t)
    red_t = []

for x in range(h):
    print("".join(matrica_rez[x]))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
g = []
for i in range(h):
  c = input()
  if '#' not in c:
    continue
  g.append(c)
h = len(g)
memo = []
for i in range(w):
  f = 1
  for j in range(h):
    if g[j][i] == '#':
      f = 0
  if f:
    memo.append(i)
for j in range(h):
  print(''.join([g[j][i] for i in range(w) if i not in memo]))

Submission status: Accepted

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

d_h = []
d_w = []
for i in range(h):
    if "#" not in ary[i]:
        d_h.append(i)
for i in range(w):
    if "#" not in ary[:,i]:
        d_w.append(i)

ary = np.delete(ary, d_h, 0)
ary = np.delete(ary, d_w, 1)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#H = int(input())
H, W = map(int, input().split())
A = []
for _ in range(H) :
  A.append(list(str(input())))
#print (A)

for i in range(H) :
  wcnt = 0
  for j in range(W) :
    if A[i][j] == "." :
      wcnt += 1
  if wcnt == W :
    for j in range(W) :
      A[i][j] = "0"
#print (A)

for j in range(W) :
  wcnt = 0
  for i in range(H) :
    if A[i][j] == "." or A[i][j] == "0":
      wcnt += 1
  if wcnt == H :
    for i in range(H) :
      A[i][j] = "0"
#print (A)

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

Submission status: Accepted

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

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

hm = []
for i in range(h):
    if board[i] == '.' * w:
        hm.append(i)

wm = []
for i in range(w):
    for j in range(h):
        if board[j][i] != '.':
            break
        if j == h-1:
            wm.append(i)


for i in range(h):
    for j in range(w):
        if i not in hm and j not in wm:
            print(board[i][j], end='')
    if i not in hm:
        print()

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, W = list(map(int, sys.stdin.buffer.readline().split()))
S = [list(sys.stdin.buffer.readline().decode().rstrip()) for _ in range(H)]

S = np.array(S, dtype='U1')
ans = []
for s in S:
    if '#' in s:
        ans.append(s)
S = np.array(ans, dtype='U1')
ans = []
for s in S.T:
    if '#' in s:
        ans.append(s)
ans = np.array(ans, dtype='U1').T
for r in ans:
    print(''.join(r))

Submission status: Accepted

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

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

aT = list(zip(*a))
aT = [x for x in aT if "#" in x]

a = list(zip(*aT))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a,c=[],[]
for i in range(h):
    a.append(input())
for i in range(w):
    b=0
    for j in range(h):
        if a[j][i]=='#':
            b=1
    c.append(b)
for i in range(h):
    if a[i]=='.'*w:
        continue
    for j in range(w):
        if c[j]==1:
            print(a[i][j],end='')
    print('')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    li=list(input())
    a.append(li)
for i in range(w):
    b=0
    for j in range(h):
        if a[j][i]=='.':
            b+=1
    if b==h:
        for k in range(h):
            a[k][i]=''
for j in range(h):
    if a[j].count('#')!=0:
        print(''.join(a[j]))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
#h+w回確認する
import numpy as np
change_h=0
change_w=w
ans=[]
for i in range(h):
    if l[i].count('.')!=w:
        ans+=[l[i][:]]
        change_h+=1
l_count=[]
for i in range(w):
    count=0
    for j in range(h):
        if l[j][i]=='.':
            count+=1
    
    if count==h:
        l_count+=[i]
    
l_count=sorted(l_count,reverse=True)#削除したい列番号を後ろから削除する
for i in l_count:
    ans=np.delete(ans,i,axis=1)
    #np.delete(a,b,c):a:配列,b:削除したい行・列番号,c:列か行か

#最後の出力
for i in range(change_h):
    print(*ans[i],sep='')

Submission status: Accepted

Solution code:
# coding: utf-8

(row_count, col_count) = [int(i) for i in input().rstrip().split(" ")]

def shrink_col(map):
    new_map = [[] for i in range(len(map))]
    for i in range(col_count):
        all_space = True
        for j in range(len(map)):
            if map[j][i] == '#':
                all_space = False
                break
        if not all_space:
            for j in range(len(map)):
                new_map[j].append(map[j][i])
    return new_map

def shrink_row(map):
    new_map = []
    for i in range(row_count):
        if len([j for j in map[i] if j == "#"]) > 0:
            new_map.append(map[i])
    return new_map


map = [input().rstrip() for i in range(row_count)]
map = shrink_row(map)
map = shrink_col(map)

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

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())

A = []
for i in range(h):
    s = list(input())
    if len(set(s)) == 1 and s[0] == ".":
        continue
    else:
        A.append(s)
B = A
c = 0
for i in range(w):
    s = []
    for j in range(len(A)):
        s.append(A[j][i])
    if len(set(s)) == 1 and s[0] == '.':
        B = np.delete(B, i-c, 1)
        c += 1


for i in B:
    a = ""
    for j in i:
        a += j
    print(a)

Submission status: Accepted

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

grid = []

for _ in range(H):
    grid.append(input())

Hx = [ (True if '#' in grid[i] else False) for i in range(H) ]
Wx = [ (True if '#' in [grid[j][i] for j in range(H)] else False) for i in range(W) ]

for i in range(H):
    flag = False
    for j in range(W):
        if(Hx[i] and Wx[j]):
            flag = True
            print(grid[i][j], sep='', end='')
    if flag:
        print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
s=[list(input()) for i in range(H)]
def ts(s):
  ss=[]
  for i in range(len(s)):
    if s[i] != ["."]*len(s[i]):
      ss.append(s[i])
  return ss
sH = ts(s)
sH = list(map(list,zip(*sH)))
sW = ts(sH)
sW = list(map(list,zip(*sW)))
for i in range(len(sW)):
  print("".join(sW[i]))

Submission status: Accepted

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

for i in range(h):
    if ''.join(a[i-tmp]) == '.'*w:
        del a[i-tmp]
        tmp += 1

for i in range(w):
    lst = []
    for j in range(h-tmp):
        lst.append(a[j][i-cnt])
    if ''.join(lst)=='.'*(h-tmp):
        for k in range(h-tmp):
            del a[k][i-cnt]
        cnt += 1

for i in range(h-tmp):
    print(''.join(a[i]))

Submission status: Accepted

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

memo = []

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

ls = [["" for _ in range(len(memo))] for _ in range(w)]

for i in range(w):
    for j in range(len(memo)):
        ls[i][j] = memo[j][i]

memo = []

for i in range(w):
    if ls[i] != ["."] * len(ls[i]):
        memo.append(ls[i])

ans = [["" for _ in range(len(memo))] for _ in range(len(memo[0]))]

for i in range(len(memo[0])):
    for j in range(len(memo)):
        ans[i][j] = memo[j][i]


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

Submission status: Accepted

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

for i in range(H):
	mas.append(list(map(str, input())))
	
for i in range(H):
	flg = 1
	for j in range(W):
		if mas[i][j] == "#":
			flg = 0
			break
	if flg:
		cut_h.append(i)
		
for i in range(W):
	flg = 1
	for j in range(H):
		if mas[j][i] == "#":
			flg = 0
			break
	if flg:
		cut_w.append(i)
		
for i in range(H):
	flg = 1
	for j in range(W):
		if i in cut_h:
			flg = 0
			continue
		if j in cut_w: continue
		print(mas[i][j], end = "")
	if flg:
		print()

Submission status: Accepted

Solution code:
h, w = [int(n) for n in input().split()]
grid = [input() for _ in range(h)]
row_hashs = set()
column_hashs = set()

for i, row in enumerate(grid):
    for j, ch in enumerate(row):
        if ch == '#':
            row_hashs.add(i)
            column_hashs.add(j)

new_grid = []

for i, row in enumerate(grid):
    if i not in row_hashs:
        continue
    new_grid.append([])
    for j, ch in enumerate(row):
        if j not in column_hashs:
            continue
        new_grid[-1].append(ch)
    new_grid[-1] = "".join(new_grid[-1])

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

Submission status: Accepted

Solution code:
hori_verti = input().split()
horisontal = int(hori_verti[0])
vertical = int(hori_verti[1])
input_grid = [input() for element in range(horisontal)]

remove_yoko_list = set()
remove_tate_list = set()

def scan(grid_verti_list):
  for ele in grid_verti_list:
    if ele != '.':
      return False
  return True

def scan_column():
  for tate in range(vertical):
    row = []
    for yoko in range(horisontal):
      row.append(input_grid[yoko][tate])
    if scan(row):
      remove_tate_list.add(tate)      

for hori_num in range(horisontal):
  grid_verti_list = input_grid[hori_num]
  if scan(list(grid_verti_list)):
    remove_yoko_list.add(hori_num)
    
scan_column()

res = []
for x in range(horisontal):
  keep = []
  if x in remove_yoko_list:
    continue
  for (y, letter) in enumerate(input_grid[x]):
    if y in remove_tate_list:
      continue
    keep.append(letter)
  res.append(keep)
      
result = []  
for str in res:
  new_line_list = ''.join(str)
  result.append(new_line_list)

if(len(result) == 0):
  print('\n'.join(input_grid))
else:
  print('\n'.join(result))

Submission status: Accepted

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

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

for j in range(w):
    for i in range(h):
        if a[i][j] == "#":
            break
    else:
        lstj.append(j)

for i in range(h):
    for j in range(w):
        if i not in lsti and j not in lstj:
            print(a[i][j],end = "")
    else:
        if i not in lsti:
            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:
import sys
input = sys.stdin.readline
H, W = [int(x) for x in input().split()]
a = []
for _ in range(H):
    a.append(list(input().rstrip()))
import numpy as np
a = np.array(a, np.object)
a = a.T
retsu = []
gyou = []
for i in range(W):
    if "#" not in a[i]:
        retsu.append(i)
a = a.T
for i in range(H):
    if "#" not in a[i]:
        gyou.append(i)
a = np.delete(a, retsu, 1)
a = np.delete(a, gyou, 0)
for j in a:
    j = list(j)
    print("".join(j))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for _ in [0]*h:
    ai=list(input())
    #print(ai)
    if "#" in ai:
        a.append(ai)
t=[]
for wi in zip(*a):
    if "#" in wi:
        t.append(wi)
for ans in zip(*t):
    print("".join(ans))

Submission status: Accepted

Solution code:
h, w = [int(n) for n in input().split()]
grid = [input() for _ in range(h)]
row_hashs = set()
column_hashs = set()

for i, row in enumerate(grid):
    for j, ch in enumerate(row):
        if ch == '#':
            row_hashs.add(i)
            column_hashs.add(j)

new_grid = []

for i, row in enumerate(grid):
    if i not in row_hashs:
        continue
    new_grid.append([])
    for j, ch in enumerate(row):
        if j not in column_hashs:
            continue
        new_grid[-1].append(ch)
    new_grid[-1] = "".join(new_grid[-1])


print("\n".join(new_grid))
# print(*new_grid, sep="\n")

Submission status: Accepted

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

A = [input() for i in range(H)]

row = []
column = []

for i in range(len(A)):
        for j in range(len(A[i])):
                if A[i][j] == "#":
                        row.append(i)
                        break

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


for i in range(len(A)):
        flag = True
        for j in range(len(A[i])):
                if i in row:
                        if j in column:
                                print(A[i][j], end = "")
                else:
                        flag = False
                        continue
        if flag:
                print("")

Submission status: Accepted

Solution code:
def main():
    H, W = [int(i) for i in input().split()]
    grid = [list(input()) for _ in range(H)]
    grid = [l for l in grid if "#" in l]
    grid = list(zip(*grid))
    grid = [l for l in grid if "#" in l]
    grid = ["".join(l) for l in zip(*grid)]
    print(*grid, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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:
a,b = [int(i) for i in input().split()]
l = [input() for _ in range(a)]
skip_num = []

for i in range(b):
    key_set = set()
    for j in range(a):
        key_set |= set(l[j][i])
    if key_set == set('.'):
        skip_num.append(i)
        

ans = [[] for _ in range(a)]       
for k in range(a):
    if set(l[k]) ==  set('.'):
        pass
    else:
        for i in range(b):
            if i in skip_num :
                pass
            else:
                ans[k].append(l[k][i])
                

for i in ans:
    if i :
        print(''.join(i))

Submission status: Accepted

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

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

remove_list = []
# print(A)
for i in range(W):
    if A[0][i] == ".":
        aa = A[0][i]
        flag = 0
        for a in A:
            if aa != a[i]:
                flag = 1
                break
        if flag == 0:
            remove_list.append(i)

# print(remove_list)

for a in A:
    print_list = []
    for idx, a_ in enumerate(a):
        if idx not in remove_list:
            print_list.append(a_)
    print("".join(print_list))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
arr = list(list(input()) for _ in range(n))
rmv_row = [1] * n
rmv_col = [1] * m
for i in range(n):
    for j in range(m):
        if arr[i][j] == '#':
            rmv_row[i] = 0
            rmv_col[j] = 0
for i in range(n):
    if rmv_row[i] == 1:
        continue
    for j in range(m):
        if rmv_col[j] == 1:
            continue
        print(arr[i][j], end='')
    print()

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())
a_complex = []
for i in range(h):
    a_row = list(input())
    a_complex+=[a_row]

#print(a_complex)
count = 0
for i in range(h):
    if not ("#" in a_complex[i-count]):
        del a_complex[i-count]
        count += 1
#print(a_complex)
ver = []
count = 0
for i in range(w):#列
    for j in range(len(a_complex)):  #行
        ver += [a_complex[j][i-count]]
    if not ("#" in ver):
        for u in range(len(a_complex)):
            del a_complex[u][i - count]
        count+=1
    ver = []
#print(a_complex)
for i in range(len(a_complex)):
    for j in range(len(a_complex[0])):
        print(a_complex[i][j], end="")
    print("")

Submission status: Accepted

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

# matrix = []
# for _ in range(h):
#     row = input()
#     if '#' not in row:
#         continue
#     else:
#         matrix.append(row)

# print(matrix)

matrix = [input() for _ in range(h)]
# print(matrix)
matrix = [row for row in matrix if '#' in row]
# print(matrix)

T_matrix = [col for col in zip(*matrix) if '#' in col]
# print(T_matrix)

# T_matrix = []

# for col in zip(*matrix):
#     if '#' not in col:
#         continue
#     else:
#         T_matrix.append(col)

# for row in matrix:
#     print(row)
# for row in zip(*T_matrix):
#     print(''.join(row))

print(*(''.join(row) for row in zip(*T_matrix)), sep='\n')